#include <bits/stdc++.h>
using namespace std;
int n, m, res = 0;
string a[105];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      int j = 0;
      for (; j < m; j++)
        if (a[i][j] > a[i + 1][j]) break;
      for (int k = 0; k < n; k++) a[k].erase(j, 1);
      res++;
      m--;
      i = -1;
    }
  }
  cout << res;
  return 0;
}
