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.
#https://codeforces.com/problemset/problem/496/C
#1500分
#21:52-

n, m = map(int, input().split())
items = []
for _ in range(n):
    items.append(input())

if n == 1:
    print("0")
else:
    #考虑到1 ≤ n, m ≤ 100 => 即使直接采用暴力算法，复杂度也ok（n * m）
    ans = 0
    def judge(items):
        for i in range(1, n):
            if items[i] < items[i-1]:
                return True
        return False
    #从左往右遍历
    #判断当前是否还需要继续
    while judge(items):
        #找出要删除的列（从左边开始找）
        deleted_cols = -1
        for j in range(m - ans):
            for i in range(1, n):
                if items[i][j] < items[i-1][j]:
                    deleted_cols = j
                    break
            if deleted_cols != -1:
                break
        #print("deleted_cols: ", deleted_cols)
        for i in range(n):
            items[i] = items[i][:deleted_cols] + items[i][deleted_cols+1:]
        #print("after delete: ", items)
        ans += 1
    print(ans)