#include <bits/stdc++.h>
int main() {
  int n, m, b[110], l = 0, j, z = 0, k, i;
  char a[110][110];
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", a[i]);
  do {
    z = l;
    for (i = 1; i < n; i++) {
      for (j = 0; j < m; j++) {
        for (k = 0; k < l; k++)
          if (j == b[k]) break;
        if (k == l) {
          if (a[i][j] > a[i + 1][j])
            b[l++] = j;
          else if (a[i][j] < a[i + 1][j])
            break;
        }
      }
    }
  } while (l != z);
  printf("%d\n", l);
  return 0;
}
