#include <bits/stdc++.h>
const int N = 105;
int n, m, pn, qn;
int f[26], p[N], q[N];
char s[N][N];
bool ok(int y) {
  int i, x, z, v;
  qn = 0;
  for (i = 0; i < pn - 1; i++) {
    z = -1;
    for (x = p[i]; x < p[i + 1]; x++) {
      v = s[x][y] - 'a';
      if (v < z) return 0;
      if (v > z) {
        q[qn++] = x;
        z = v;
      }
    }
  }
  q[qn++] = n;
  pn = qn;
  for (i = 0; i < qn; i++) {
    p[i] = q[i];
  }
  return 1;
}
int main() {
  int i, z;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  pn = 2;
  p[0] = 0;
  p[1] = n;
  z = 0;
  for (i = 0; i < m; i++) {
    if (ok(i)) z++;
  }
  printf("%d\n", m - z);
  return 0;
}
