#include <bits/stdc++.h>
using namespace std;
char S[200][200];
int N, M, ans;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%s", S[i] + 1);
  }
  vector<string> A(N + 1);
  for (int i = 1; i <= M; i++) {
    vector<pair<string, int> > B(N + 1);
    for (int j = 1; j <= N; j++) {
      B[j].first = A[j] + S[j][i];
      B[j].second = j;
    }
    sort(B.begin() + 1, B.end());
    bool ok = 1;
    for (int j = 1; j <= N; j++) {
      if (B[j].second != j) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      ans++;
      for (int j = 1; j <= N; j++) {
        A[j] = B[j].first;
      }
    }
  }
  ans = M - ans;
  printf("%d\n", ans);
  return 0;
}
