#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<string> s(n), t(n);
    for (auto& v : s) cin >> v;
    int res = 0;
    for (int i = 0; i < m; ++i) {
      bool ok = true;
      for (int j = 1; j < n; ++j)
        if (t[j] + s[j][i] < t[j - 1] + s[j - 1][i]) ok = false;
      if (ok) {
        for (int j = 0; j < n; ++j) t[j] += s[j][i];
      } else {
        ++res;
      }
    }
    cout << res << endl;
  }
}
