#include <bits/stdc++.h>
const int MAXN = 105;
char s[MAXN][MAXN];
int good[MAXN];
int main(void) {
  int n, m;
  int res = 0;
  scanf(" %d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf(" %s", s[i]);
  }
  for (int j = 0; j < m; j++) {
    int rem = 0;
    for (int i = 0; i < n; i++) {
      if (good[i]) {
        continue;
      }
      for (int k = i - 1; k >= 0; k--) {
        if (s[k][j] > s[i][j]) {
          rem = 1;
        }
        if (good[k]) {
          break;
        }
      }
    }
    res += rem;
    if (rem == 0) {
      for (int i = 0; i < n; i++) {
        for (int k = i - 1; k >= 0; k--) {
          if (s[k][j] < s[i][j]) {
            good[i] = 1;
          }
          break;
        }
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
