#include <bits/stdc++.h>
int val[102], aux[102];
char m[102][102];
int main() {
  int nrlin, nrcol;
  scanf("%d%d ", &nrlin, &nrcol);
  for (int i = 1; i <= nrlin; i++) {
    for (int j = 1; j <= nrcol; j++) m[i][j] = fgetc(stdin);
    fgetc(stdin);
  }
  for (int i = 1; i <= nrlin; i++) val[i] = 1;
  int ans = 0, k = 1;
  for (int j = 1; j <= nrcol; j++) {
    bool f = 1;
    for (int i = 2; i <= nrlin; i++)
      if ((val[i] == val[i - 1]) && (m[i][j] < m[i - 1][j])) f = 0;
    if (f) {
      ans++;
      for (int i = 1; i <= nrlin; i++) {
        if ((val[i] == val[i - 1]) && (m[i][j] == m[i - 1][j]))
          aux[i] = k;
        else {
          k++;
          aux[i] = k;
        }
      }
      for (int i = 1; i <= nrlin; i++) val[i] = aux[i];
    }
  }
  ans = nrcol - ans;
  printf("%d\n", ans);
  return 0;
}
