#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> v;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    v.push_back(str);
  }
  int ct = 0;
  vector<int> bigger(n, 0);
  for (int i = 0; i < m; i++) {
    int j;
    for (j = 1; j < n; j++) {
      if (bigger[j]) continue;
      if (v[j - 1][i] > v[j][i]) {
        ct++;
        break;
      }
    }
    if (j == n) {
      for (int k = 1; k < n; k++) {
        if (bigger[k]) continue;
        if (v[k - 1][i] < v[k][i]) bigger[k] = 1;
      }
    }
  }
  cout << ct << endl;
  return 0;
}
