#include <bits/stdc++.h>
using namespace std;
char a[1111][1111];
int n, m;
int del[1111];
int main() {
  gets(a[0]);
  sscanf(a[0], "%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    gets(a[i]);
  }
  while (1) {
    bool upd = 0;
    for (int i = 0; i < n - 1; ++i) {
      for (int j = 0; j < m; ++j) {
        if (!del[j]) {
          if (a[i + 1][j] < a[i][j]) {
            upd = 1;
            del[j] = 1;
          } else if (a[i + 1][j] > a[i][j])
            break;
        }
      }
    }
    if (!upd) break;
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) ans += del[i];
  cout << ans << endl;
}
