#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  bool ch = true;
  while (ch) {
    ch = false;
    for (int i = 1; i < n; ++i) {
      for (size_t j = 0; j < s[i].length(); ++j) {
        if (s[i][j] < s[i - 1][j]) {
          for (int k = 0; k < n; ++k) s[k].erase(s[k].begin() + j);
          ++ans;
          ch = true;
          break;
        } else if (s[i][j] > s[i - 1][j])
          break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
