#include <bits/stdc++.h>
using namespace std;
const int M = 1003;
const int Q = 1e9 + 7;
const long double eps = 1e-2;
const long double pi = 3.141592653589793238;
char s[M][M];
bool used[M];
int main() {
  srand(time(NULL));
  int n, m, i, j, ans = 0;
  bool ok;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  for (j = 0; j < m; j++) {
    ok = true;
    for (i = 0; i < n - 1; i++) {
      if (!used[i] && s[i][j] > s[i + 1][j]) {
        ok = false;
        break;
      }
    }
    if (!ok) {
      ans++;
    } else {
      for (i = 0; i < n - 1; i++)
        if (s[i][j] < s[i + 1][j]) used[i] = true;
    }
  }
  printf("%d", ans);
  return 0;
}
