#include <bits/stdc++.h>
using namespace std;
int n, m, vis[111];
char s[111][111];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    bool fg = 1;
    for (int j = 0, lst = 0; j < n; j++) {
      if (s[j][i] < lst) {
        fg = 0;
        break;
      }
      lst = s[j][i];
      if (vis[j]) lst = 0;
    }
    if (fg) {
      ans++;
      for (int j = 1; j < n; j++) {
        if (s[j][i] > s[j - 1][i]) vis[j - 1] = 1;
      }
    }
  }
  cout << m - ans << endl;
  return 0;
}
