#include <bits/stdc++.h>
using namespace std;
char s[1005][1005];
int mark[1005];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    int cnt = 0;
    memset(mark, 0, sizeof(mark));
    for (int i = 0; i < m; i++) {
      int sign = 1;
      for (int j = 1; j < n; j++) {
        if (s[j][i] < s[j - 1][i] && mark[j] == 0) {
          cnt++;
          sign = 0;
          break;
        }
      }
      if (!sign) continue;
      for (int j = 1; j < n; j++)
        if (s[j][i] > s[j - 1][i]) mark[j] = 1;
    }
    printf("%d\n", cnt);
  }
}
