#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<string> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  int cur = 0;
  int curB = 0;
  set<int> ans;
  for (int i = 0; i < xs.size() - 1; i++) {
    int j = 0;
    while (j < xs[i].size()) {
      if (xs[i][j] != xs[i + 1][j] && !ans.count(j)) {
        break;
      }
      j++;
    }
    if (j < m && xs[i][j] > xs[i + 1][j]) {
      ans.insert(j);
      i = -1;
    }
  }
  cout << ans.size();
  return 0;
}
