#include <bits/stdc++.h>
using namespace std;
int b[105];
int c[105];
int main() {
  int n, m, i, j, k, ans = 0, f;
  vector<string> a;
  string s;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    c[i] = 0;
    cin >> s;
    a.push_back(s);
  }
  for (i = 0; i < m; i++) {
    f = 1;
    b[0] = 1;
    for (j = 1; j < n; j++) {
      if (c[j]) continue;
      if (a[j][i] == a[j - 1][i]) {
        b[j] = b[j - 1];
      } else if (a[j][i] > a[j - 1][i]) {
        b[j] = b[j - 1] + 1;
      } else {
        f = 0;
        break;
      }
    }
    if (f == 1) {
      for (j = 1; j < n; j++) {
        if (b[j] > b[j - 1]) c[j] = 1;
      }
    } else {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
