#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int MODULO = 1000 * 1000 * 1000 + 7;
const int MAXN = 1005;
int n, m;
char c[MAXN][MAXN];
bool lesss[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c[i][j];
  int res = 0;
  for (int j = 0; j < m; j++) {
    bool ok = true;
    for (int i = 0; i + 1 < n; i++) ok &= lesss[i] || c[i][j] <= c[i + 1][j];
    if (ok) {
      for (int i = 0; i + 1 < n; i++) lesss[i] |= c[i][j] < c[i + 1][j];
    } else
      res++;
  }
  cout << res;
  return 0;
}
