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())

lines = []
for _ in range(n_lines):
    lines.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_cols(lines):
    if len(lines) < 2:
        return None

    return pivot_cols_rec(lines)

def pivot_cols_rec(lines):
    if lines not in pivot_cols_rec.memo:
        if len(lines) == 1:
            res = [] if is_sorted(lines[0]) else [0]
        else:
            res = pivot_cols_rec(lines[0:1])[:]
            res.extend(map(lambda n: n + 1, pivot_cols_rec(lines[1:])))

        pivot_cols_rec.memo[lines] = res

    return pivot_cols_rec.memo[lines]
pivot_cols_rec.memo = {(): 0}

min_steps = 100
def do_rec(lines, level = 0, memo = True):
    global min_steps
    if level >= min_steps:
        return None

    if not lines:
        return level

    if memo:
        key = lines
        if key not in do_rec.memo:
            do_rec.memo[key] = do_rec(lines, level, False)

        return do_rec.memo[key]

    if is_sorted(lines):
        return level

    pivots = pivot_cols(lines)
    for i in pivots:        
        n_lines = tuple(s[0:i] + s[i+1:] for s in lines)
        steps = do_rec(n_lines, level + 1)
        if steps is not None:
            min_steps = min(steps, min_steps)
            
    return min_steps
do_rec.memo = dict()

print(do_rec(tuple(lines)))


