#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char arr[120][120];
  vector<string> v;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    v.push_back("a");
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  int ans = 0;
  for (int j = 0; j < m; j++) {
    int flag = 0;
    for (int i = 0; i < (n - 1); i++) {
      if ((v[i] + arr[i][j]) > (v[i + 1] + arr[i + 1][j])) {
        ans++;
        flag++;
        break;
      }
    }
    if (flag != 0) continue;
    for (int i = 0; i < n; i++) {
      v[i] += arr[i][j];
    }
  }
  cout << ans << endl;
  return 0;
}
