#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool c[n];
  memset(c, 0, sizeof(c));
  int ans = 0;
  bool flag = 0;
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      if (a[i][j] < a[i - 1][j] && !c[i]) {
        flag = 1;
      }
    }
    if (flag) {
      ans++;
    } else {
      for (int i = 1; i < n; i++) {
        if (a[i][j] > a[i - 1][j]) {
          c[i] = 1;
        }
      }
    }
    flag = 0;
  }
  cout << ans << endl;
  return 0;
}
