#include <bits/stdc++.h>
using namespace std;
int n, m, v[110];
char s[110][110];
int solve(int x) {
  int cnt = 0;
  char s1[110], s2[110];
  for (int i = 0; i <= x; i++) {
    if (!v[i]) s1[cnt++] = s[0][i];
  }
  s1[cnt] = '\0';
  for (int r = 1; r < n; r++) {
    cnt = 0;
    for (int i = 0; i <= x; i++) {
      if (!v[i]) s2[cnt++] = s[r][i];
    }
    s2[cnt] = '\0';
    if (strcmp(s1, s2) > 0) return 1;
    swap(s1, s2);
  }
  return 0;
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%s", s[i]);
    }
    memset(v, 0, sizeof(v));
    int ans = 0;
    for (int i = 0; i < m; i++) {
      if (solve(i)) {
        ans++;
        v[i] = 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
