#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  vector<string> s(n);
  vector<pair<string, int> > u(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    u[i].second = i;
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    vector<pair<string, int> > k = u;
    for (int j = 0; j < n; j++) {
      k[j].first.push_back(s[j][i]);
    }
    sort(k.begin(), k.end());
    bool can = false;
    for (int j = 0; j < n; j++) {
      can |= k[j].second != j;
    }
    if (!can) {
      u = k;
    }
    ans += can;
  }
  cout << ans << endl;
  return 0;
}
