#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string A[n + 1];
  for (int i = 1; i <= n; i++) cin >> A[i];
  int res = 0;
  for (int i = 1; i < n; i++) {
    if (A[i] > A[i + 1]) {
      int j = 0;
      for (j = 0; j < m - 1; j++)
        if (A[i][j] > A[i + 1][j]) break;
      for (int f = 1; f <= n; f++) A[f].erase(j, 1);
      res++;
      m--;
      i = -1;
    }
  }
  cout << res;
}
