#include <bits/stdc++.h>
using namespace std;
bool comp(string s, string t, vector<int> rows) {
  int i = 0;
  int m = s.size();
  while (i < m &&
         (s[i] == t[i] || (find(rows.begin(), rows.end(), i) != rows.end())))
    i++;
  if (i == m) return false;
  return s[i] < t[i];
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> table(n);
  for (int i = 0; i < n; i++) cin >> table[i];
  vector<int> rows;
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      int k = i - 1;
      if (comp(table[i], table[k], rows)) {
        for (int l = 0; l < m; l++) {
          if (find(rows.begin(), rows.end(), l) != rows.end()) continue;
          if (table[i][l] < table[k][l]) {
            rows.push_back(l);
            break;
          }
        }
      }
    }
  }
  cout << rows.size() << endl;
  return 0;
}
