#include <bits/stdc++.h>
using namespace std;
int N, M;
inline int read() {
  long long int x;
  scanf("%lld", &x);
  return x;
}
char q[150][150], used[150];
int main() {
  int top = 0;
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) scanf(" %c", &q[i][j]);
  for (int j = 1; j <= M; j++) {
    int con = 0;
    for (int i = 1; i < N; i++) {
      if (!used[i]) {
        if (q[i][j] > q[i + 1][j]) {
          con = 1;
          top++;
          break;
        }
      }
    }
    if (con) continue;
    for (int i = 1; i < N; i++)
      if (q[i][j] < q[i + 1][j]) used[i] = 1;
  }
  cout << top;
  puts("");
  ;
  return 0;
}
