#include <bits/stdc++.h>
using namespace std;
int main() {
  char ar[1002][1002];
  int n, m, i, j, count, ar1[1002];
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%s", ar[i]);
  }
  for (i = 0; i < m; i++) {
    ar1[i] = 1;
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (ar1[j] == 1) {
        if (ar[i][j] < ar[i - 1][j]) {
          ar1[j] = 0;
          i = 0;
          break;
        }
        if (ar[i][j] > ar[i - 1][j]) {
          break;
        }
      }
    }
  }
  count = 0;
  for (i = 0; i < m; i++) {
    count += 1 - ar1[i];
  }
  printf("%d\n", count);
  return 0;
}
