#include <bits/stdc++.h>
using namespace std;
const int N = 200;
int flag[N], now[N];
int main() {
  int n, m;
  string s[N];
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) cin >> s[i];
    memset(now, 0, sizeof(now));
    int ans = 0;
    for (int i = 0; i < m; i++) {
      int ok = 1;
      memset(flag, 0, sizeof(flag));
      for (int j = 0; j < n - 1 && ok; j++) {
        if (now[j]) continue;
        if (s[j][i] > s[j + 1][i]) {
          ans++;
          ok = 0;
          break;
        } else if (s[j][i] < s[j + 1][i])
          flag[j] = true;
      }
      if (ok) {
        for (int j = 0; j < n; j++)
          if (flag[j]) now[j] = 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
