#include <bits/stdc++.h>
using namespace std;
bool vis[1009];
string v[1009];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> v[i];
  int ans = 0;
  memset(vis, 0, sizeof(vis));
  while (true) {
    bool stop = 1;
    for (int i = 0; i < n - 1; ++i) {
      for (int j = 0; j < m; ++j) {
        if (vis[j]) continue;
        if (v[i][j] < v[i + 1][j]) break;
        if (v[i][j] > v[i + 1][j]) {
          stop = 0;
          ++ans;
          vis[j] = 1;
        }
      }
    }
    if (stop) break;
  }
  cout << ans << "\n";
  return 0;
}
