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