#include <bits/stdc++.h>
char a[100][100];
int x[100], y[100];
int main() {
  int n, m, i, j, c, q = 0, flag;
  scanf("%d %d", &n, &m);
  c = getchar();
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%c", &a[i][j]);
    }
    c = getchar();
  }
  for (j = 0; j < m; j++) {
    for (i = 0; i < n - 1; i++) {
      if (x[j] != 1) {
        if (a[i][j] < a[i + 1][j]) {
          if (y[i] == 0)
            y[i] = j + 1;
          else if (x[y[i] - 1] == 1)
            y[i] = j + 1;
        } else if (a[i][j] > a[i + 1][j]) {
          if (y[i] > 0) {
            if (x[y[i] - 1] == 1) {
              x[j] = 1;
              break;
            }
          } else {
            x[j] = 1;
            break;
          }
        }
      }
    }
  }
  for (i = 0; i < m; i++) {
    if (x[i] == 1) q++;
  }
  printf("%d\n", q);
  return 0;
}
