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