#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[1100][1100];
bool flag[1100];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int tmp = 0;
    for (int j = 1; j < n; j++) {
      if (!flag[j]) {
        if (s[j][i] < s[j - 1][i])
          tmp |= 1;
        else if (s[j][i] == s[j - 1][i])
          tmp |= 2;
      }
    }
    if (tmp & 1)
      ans++;
    else if (tmp & 2) {
      for (int j = 1; j < n; j++)
        if (s[j][i] > s[j - 1][i]) flag[j] = true;
    } else
      break;
  }
  printf("%d\n", ans);
}
