#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int ans = 0;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int x = 0; x < (int)s[0].length(); x++) {
    bool sorted = 1;
    for (int j = 0; j < n - 1; j++) {
      if (s[j].substr(0, x + 1) > s[j + 1].substr(0, x + 1)) {
        sorted = 0;
      }
    }
    if (!sorted) {
      ans++;
      for (int j = 0; j < n; j++) {
        string new_string;
        for (int k = 0; k < (int)s[j].length(); k++) {
          if (k != x) {
            new_string += s[j][k];
          }
        }
        s[j] = new_string;
      }
      --x;
    }
  }
  cout << ans << "\n";
  return 0;
}
