#include <bits/stdc++.h>
using namespace std;
int m, n;
char s[1200][1200];
vector<pair<int, int> > v, t;
int CTRL(int a, int b, int j) {
  for (long long int i = a; i <= b - 1; i++)
    if (s[i + 1][j] < s[i][j]) return 1;
  return 0;
}
int ctrl(int j) {
  for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
    if (CTRL(it->first, it->second, j)) return 1;
  return 0;
}
int main() {
  cin >> m >> n;
  for (long long int i = 1; i <= m; i++) scanf("%s", s[i] + 1);
  int res = 0;
  v.push_back(make_pair(1, m));
  for (long long int i = 1; i <= n; i++) {
    if (ctrl(i)) {
      res++;
      continue;
    }
    t.clear();
    for (typeof(v.begin()) it = v.begin(); it != v.end(); it++) {
      for (long long int j = it->first; j <= it->second; j++) {
        int b = j;
        while (b < it->second and s[j][i] == s[b + 1][i]) b++;
        t.push_back(make_pair(j, b));
        j = b;
      }
    }
    v = t;
  }
  cout << res << endl;
}
