#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t n, m, i, j, ans;
  cin >> n >> m;
  string str[n + 1];
  map<int64_t, int64_t> ok;
  for (i = 1; i <= n; i++) {
    cin >> str[i];
    ok[i] = false;
  }
  ok[1] = true;
  j = 0;
  ans = 0;
  bool flag;
  while (j < m) {
    vector<int64_t> v;
    flag = true;
    for (i = 2; i <= n; i++) {
      if (!ok[i] and str[i][j] > str[i - 1][j]) v.push_back(i);
      if (!ok[i] and str[i][j] < str[i - 1][j]) flag = false;
    }
    if (flag) {
      for (auto k : v) ok[k] = true;
    } else
      ans++;
    j++;
  }
  cout << ans << endl;
  return 0;
}
