#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[100];
  int n, m, e[100] = {}, c = 0, f;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    f = 1;
    for (int j = 0; j < n - 1; j++)
      if (e[j] == 0 && s[j][i] > s[j + 1][i]) {
        f = 0;
        break;
      }
    if (!f) {
      c++;
      continue;
    }
    for (int j = 0; j < n - 1; j++)
      if (s[j][i] < s[j + 1][i]) e[j] = -1;
  }
  cout << c;
}
