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.
n_lines, n_cols = map(int, input().split())

cols = []
for _ in range(n_lines):
    cols.append(input())

def is_sorted(l):
    l = iter(l)
    prev = next(l, None)
    if prev is None:
        return True

    while True:
        cur = next(l, None)
        if cur is None:
            break
        elif cur < prev:
            return False
        prev = cur

    return True

def pivot_col(cols):
    if not len(cols):
        return None

    for i in range(len(cols[0])):
        col = cols[i]
        if col in pivot_col.memo:
            ok = pivot_col.memo[col]
        else:
            ok = is_sorted(map(lambda c: c[i], cols))
            pivot_col.memo[col] = ok
        if not ok:
            return i

    return None
pivot_col.memo = dict()

def do_rec(cols):
    i = pivot_col(cols)
    if i is None:
        return 0

    n_cols = [s[0:i] + s[i+1:] for s in cols]
    return 1 + do_rec(n_cols)

print(do_rec(cols))


