#include <bits/stdc++.h>
using namespace std;
int n, m, res, d[111];
string s[101];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    bool o = 1;
    for (int j = 0; j < n - 1; j++)
      if (s[j][i] > s[j + 1][i] && d[j] == 0) {
        o = 0;
        break;
      }
    if (!o) res++;
    for (int j = 0; o && j < n - 1; j++) {
      if (s[j][i] < s[j + 1][i]) d[j] = 1;
    }
  }
  cout << res;
  return 0;
}
