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.


### NOT FINISHED
# I really need to make it go from line to line:
# first, the first 2 lines should be corrected
# then, the third, and so on.

def issorted(l):
    return all(l[i] <= l[i+1] for i in range(len(l)-1))

def mainX(n,m,t):
    ans = 0
    while not issorted(t):
        remove = -1
        for i in range(len(t) - 1):
            if t[i] > t[i+1]:
                for j in range(len(t[i])):
                    if t[i][j] != t[i+1][j]:
                        remove = j
                        break
            if remove != -1:
                print(i,remove)
                break
        t = [_t[:remove] + _t[remove+1:] for _t in t]
        ans += 1
    print(ans)

def is_good(s):
    return all(s[i] <= s[i+1] for i in range(len(s)-1))
def line_is_good(a,j):
    return all(a[i][j] <= a[i+1][j] for i in range(len(a)-1))
def main5(n,m,a):
    if n <= 1 or m<=0 or is_good(a):
        print(0)
        return
    bad = []
    for i in range(0,m):
        if line_is_good(a,i):
            continue
        #if bad == []: bad.append(i)
        s = ["".join([k for b,k in enumerate(x) if b not in bad]) for x in a]
        print(i,bad)
        if is_good(s):
            print(len(bad))
            return
        else:
            bad.append(i)
    print(m)
def main6(n,m,a):
    if n <= 1 or m<=0 or is_good(a):
        print(0)
        return
    bad = []
    good = range(m)
    ans = 0
    while not is_good(a):
        remove = -1

    return
    for i in range(0,m):
        if line_is_good(a,i):
            continue
        bad.append(i)
        #print(i)
        s = ["".join([k for b,k in enumerate(x) if b not in bad]) for x in a]
        if is_good(s):
            print(len(bad))
            return
    print(m)

def main(n,m,a):
    if n <= 1 or m<=0 or is_good(a):
        print(0)
        return
    bad = []
    ans = 0
    while not is_good(a):
        remove = -1
        for i in range(n-1):
            if a[i] > a[i+1]:
                for j in range(len(a[i])):
                    if a[i][j] > a[i+1][j]:
                        remove = j
                        break
            if remove != -1:
                break
        a = [x[:remove] + x[remove+1:] for x in a]
        ans += 1
    print(ans)

def main_input():
    n,m = [int(i) for i in input().split()]
    a = [input() for s in range(n)]
    main(n,m,a)

if __name__ == "__main__":
    main_input()
