#include <bits/stdc++.h>
using namespace std;
char ar[1100][1100];
int N, M, res, used[1100];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) scanf(" %s", ar[i] + 1);
  for (int i = 1; i <= M; i++) {
    int flag = 0;
    for (int j = 1; j < N; j++) {
      if (used[j]) continue;
      if (ar[j][i] > ar[j + 1][i]) {
        flag = 1;
        break;
      }
    }
    if (!flag)
      for (int j = 1; j < N; j++)
        if (ar[j][i] < ar[j + 1][i]) used[j] = 1;
    res += flag;
  }
  cout << res << endl;
  return 0;
}
