#include <bits/stdc++.h>
using namespace std;
int n, m, mark[105];
string s[105], cur[105];
int cnt;
bool isSorted() {
  for (int i = 1; i < n; i++)
    if (cur[i] < cur[i - 1]) {
      cnt++;
      return false;
    }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cur[i] += s[i][0];
  int flag = 0;
  if (!isSorted()) flag = 1;
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (flag) {
        int len = cur[j].length();
        cur[j][len - 1] = s[j][i];
      } else
        cur[j] += s[j][i];
    }
    if (isSorted())
      flag = 0;
    else
      flag = 1;
  }
  printf("%d", cnt);
  return 0;
}
