496_C. Removing Columns
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
    
    
      
    abcd  
    edfg  
    hijk  
    

we obtain the table:
    
    
      
    acd  
    efg  
    hjk  
    

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.

Input

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.

Output

Print a single number — the minimum number of columns that you need to remove in order to make the table good.

Examples

Input

1 10
codeforces


Output

0


Input

4 4
case
care
test
code


Output

2


Input

5 4
code
forc
esco
defo
rces


Output

4

Note

In the first sample the table is already good.

In the second sample you may remove the first and third column.

In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).

Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
```python
import sys,heapq,math
from collections import defaultdict,deque
input=sys.stdin.readline




            
r,c=map(int,input().split())
grid=[]
for i in range(r):
    grid.append(input().strip())
equal=[0 for _ in range(c)]
less=[0 for _ in range(c)]
for i in range(c):
    for row in range(1,r):
        if(grid[row-1][i]==grid[row][i]):
            equal[i]=1
        elif(grid[row-1][i]>grid[row][i]):
            equal[i]=0
            break
    less[i]=1
    for row in range(1,r):
        if(equal[i]==1):
            less[i]=0
            break
        elif(grid[row-1][i]>grid[row][i]):
            less[i]=0
            break
ans=0
for i in range(c):
    if(less[i]==1):
        ans=max(ans,c-i)
        break
    elif(equal[i]==1):
        cnt=1
        l=[]
        for row in range(1,r):
            if(grid[row-1][i]==grid[row][i]):
                start=row-1
                while(row<r and grid[row-1]==grid[row][i]):
                    row+=1
                end=row
                l.append([start,end])
        
        for col in range(i+1,c):
            f=0
            ptr=0
            while(ptr<len(l)):
                start,end=l[ptr]
                ptr+=1
                for row in range(start+1,end+1):
                    if(grid[row-1][col]>grid[row][col]):
                        f=1
                        break
                if(f==1):
                    break
            if(f==0):
                cnt+=1
                ptr=0
                nl=[]
                while(ptr<len(l)):
                    start,end=l[ptr]
                    ptr+=1
                    for row in range(start+1,end+1):
                        if(grid[row-1][col]==grid[row][col]):
                            s1=row-1
                            while(row<end+1 and grid[row-1]==grid[row][col]):
                                row+=1
                            e1=row
                            nl.append([s1,e1])
                l=nl
        ans=max(ans,cnt)

                
            
print(c-ans)
```