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.
'''input
5 3
aab
aaa
aaa
aaa
aba
'''
from sys import stdin
from collections import deque


def get_segment(arr):
	pair = []
	start = 0
	end = 0
	for i in range(1, len(arr)):
		if arr[i] == arr[i - 1]:
				end = i
		else:
			pair.append([start, end])
			start = i
			end = i
	pair.append([start, end])
	return pair




def check_arr(arr):
	flag = 0
	for  i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			pass

		elif arr[i] == arr[i - 1]:
			flag = 1
		else:
			return 3
	if flag == 0:
		return 1
	else:
		return 2


def power_of_recursion(segment, index):
	# print(segment, index)
	global myset
	if index == m:
		return

	for start, end in segment:
		temp = []
		for i in range(start, end + 1):
			temp.append(matrix[i][index])
		# print(index, start, end, temp)
		t = check_arr(temp)
		if t == 1:
			continue
		elif t == 2:
			t_segment = get_segment(temp)
			# print("temp", t_segment, temp)
			power_of_recursion(t_segment, index + 1)
			
		else:
			myset.add(index)
			power_of_recursion([[start, end]], index + 1)


# main starts
n, m  = list(map(int, stdin.readline().split()))
matrix = []
for _ in range(n):
	matrix.append(stdin.readline().strip())

segment = [[0, n - 1]]
myset = set()
power_of_recursion(segment, 0)
print(len(myset))