#include <bits/stdc++.h>
using namespace std;
bool mark[110];
string a[110];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  int res = 0;
  for (long long j = 0; j < m; j++) {
    bool remove = 0;
    for (long long i = 0; i < n - 1; i++)
      if (a[i][j] > a[i + 1][j] && !mark[i]) remove = 1;
    if (remove) {
      res++;
      continue;
    }
    for (long long i = 0; i < n - 1; i++)
      if (!mark[i] && a[i][j] < a[i + 1][j]) mark[i] = true;
  }
  cout << res;
  return 0;
}
