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