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