You are given an *n* × *m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table

 

we obtain the table:

 

A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
The first line contains two integers  — *n* and *m* (1 ≤ *n*, *m* ≤ 100).

Next *n* lines contain *m* small English letters each — the characters of the table.
from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *

g   = lambda : stdin.readline().strip()
gl  = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7

n, m = gil()
s = []
for _ in range(n):
	s.append(g())

ans = 0
diff = [False]*n
diff[0] = True

for j in range(m):
	isSorted = True
	ifPartiallySorted = True if ans else False
	for i in range(1, n):
		isSorted &= s[i][j] >= s[i-1][j]
		ifPartiallySorted &= diff[i]|(s[i][j] >= s[i-1][j])

	if isSorted:
		ans += 1
		for i in range(1, n):
			diff[i] |= s[i][j] > s[i-1][j]

	elif ifPartiallySorted:
		ans += 1
		for i in range(1, n):
			diff[i] |= s[i][j] > s[i-1][j]






print(m-ans)
