#include <bits/stdc++.h>
using namespace std;
int n, m;
bool ok[105];
char s[105][105];
int ans = 0;
int main() {
  memset(ok, 0, sizeof(ok));
  scanf("%d %d\n", &n, &m);
  for (int i = 1; i <= n; i++) cin.getline(s[i], 105);
  for (int i = 0; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (!ok[j] && s[j][i] > s[j + 1][i]) {
        ans++;
        goto gg;
      }
    }
    for (int j = 1; j < n; j++) {
      if (s[j][i] < s[j + 1][i]) ok[j] = true;
    }
  gg:;
  }
  printf("%d\n", ans);
  return 0;
}
