#include <bits/stdc++.h>
using namespace std;
int n = 0, m = 0;
inline bool check(const vector<string>& ss) {
  for (int i = 0; i < n - 1; i++) {
    if (ss[i] > ss[i + 1]) return false;
  }
  return true;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int s = 0;
  vector<string> ss(n);
  vector<string> test(n);
  for (string& s : ss) cin >> s;
  for (int i = 0; i < m; i++) {
    auto curtest = test;
    for (int j = 0; j < n; j++) {
      curtest[j] += ss[j][i];
    }
    if (check(curtest)) {
      test = curtest;
    } else {
      s += 1;
    }
  }
  cout << s;
  return 0;
}
