#include <bits/stdc++.h>
int main() {
  int i, j, k, n, m, s, pl;
  char xx[101][101];
  while (~scanf("%d %d", &n, &m)) {
    s = 0;
    for (i = 0; i < n; i++) {
      scanf("%s", xx[i]);
    }
    for (i = 0; i < n - 1; i++) {
      if (strcmp(xx[i], xx[i + 1]) > 0) {
        s++;
        for (j = 0; j < m; j++) {
          if (xx[i][j] > xx[i + 1][j]) {
            pl = j;
            break;
          }
        }
        for (j = 0; j < n; j++) {
          xx[j][pl] = 'c';
        }
        i = -1;
      }
    }
    printf("%d\n", s);
  }
  return 0;
}
