#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m;
char a[1111][1111];
bool used[1111];
bool isg[1111];
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &a[i][j]);
    }
    scanf("\n");
  }
  int ans = 0;
  for (int j = 0; j < m; j++) {
    bool ok = false;
    for (int i = 0; i < n - 1; i++) {
      if (isg[i]) continue;
      if (a[i][j] > a[i + 1][j]) {
        ok = true;
        ans++;
        break;
      }
    }
    if (!ok) {
      for (int i = 0; i < n - 1; i++) {
        if (a[i][j] < a[i + 1][j]) isg[i] = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
