#include <bits/stdc++.h>
const int maxN = 2000;
int h, w;
char a[maxN][maxN];
int cur[maxN], ne[maxN];
int main() {
  assert(scanf("%d%d", &h, &w) == 2);
  for (int i = 0; i < h; ++i) {
    assert(scanf("%s", a[i]) == 1);
  }
  for (int j = 0; j < h; ++j) {
    cur[j] = 0;
  }
  int ans = 0;
  for (int i = 0; i < w; ++i) {
    bool ok = true;
    ne[0] = 0;
    for (int j = 1; j < h; ++j) {
      if (cur[j] == cur[j - 1] && a[j][i] < a[j - 1][i]) {
        ok = false;
        break;
      } else if (cur[j] != cur[j - 1] ||
                 (cur[j] == cur[j - 1] && a[j][i] > a[j - 1][i])) {
        ne[j] = ne[j - 1] + 1;
      } else {
        ne[j] = ne[j - 1];
      }
    }
    if (!ok) {
      ++ans;
      continue;
    }
    for (int j = 0; j < h; ++j) {
      cur[j] = ne[j];
    }
  }
  printf("%d\n", ans);
  return 0;
}
