#include <bits/stdc++.h>
using namespace std;
const int N = 105;
bool u[N];
char c[N][N];
int n, m, ans;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
  for (int k = 1; k <= m; k++) {
    for (int i = 1; i < n; i++) {
      for (int j = 1; j <= m; j++) {
        if (!u[j] && c[i][j] < c[i + 1][j]) break;
        if (!u[j] && c[i][j] > c[i + 1][j]) u[j] = 1;
      }
    }
  }
  for (int i = 1; i <= m; i++) ans += u[i];
  printf("%d", ans);
  return 0;
}
