#include <bits/stdc++.h>
int n, m;
char s[200][200];
int f[200];
bool one(int i, int y) {
  int j = i + 1;
  for (int x = 0; x <= y; x++)
    if (f[x] == 0) {
      if (s[i][x] == s[j][x])
        continue;
      else if (s[i][x] < s[j][x])
        return true;
      else
        return false;
    }
  return true;
}
bool judge(int x) {
  for (int i = 0; i < n - 1; i++)
    if (!one(i, x)) return false;
  return true;
}
int main(void) {
  memset(f, 0, sizeof(f));
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) gets(s[i]);
  int ans = 0;
  for (int i = 0; i < m; i++)
    if (!judge(i)) {
      f[i] = 1;
      ans++;
    }
  printf("%d\n", ans);
  return 0;
}
