#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, kol, tmp, flag[1000];
char s[1000][1000];
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (j = 0; j < m; j++) {
    tmp = 0;
    for (i = 1; i <= n - 1; i++)
      if ((s[i][j] > s[i + 1][j]) && (flag[i] == 0)) tmp = 1;
    kol += tmp;
    if (tmp == 0)
      for (i = 1; i <= n - 1; i++)
        if ((s[i][j] < s[i + 1][j]) && (flag[i] == 0)) flag[i] = 1;
  }
  cout << kol;
}
