#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 22;
int n, m, res;
bool mark[MAXN];
string s[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) {
    bool sw = true;
    for (int j = 1; j < n; j++) {
      if (mark[j]) continue;
      if (s[j][i] > s[j + 1][i]) {
        sw = false;
        break;
      }
    }
    if (!sw)
      res++;
    else {
      for (int j = 1; j < n; j++) {
        if (mark[j]) continue;
        if (s[j][i] < s[j + 1][i]) mark[j] = true;
      }
    }
  }
  cout << res;
  return 0;
}
