#include <bits/stdc++.h>
using namespace std;
int n, m, pos[1011];
char s[1011][1011];
int solve() {
  for (int i = 0, _n = (n); i < _n; i++) pos[i] = 0;
  int res = 0;
  for (int j = 0, _n = (m); j < _n; j++) {
    bool good = true;
    for (int i = 0, _n = (n - 1); i < _n; i++) {
      if (s[i][j] > s[i + 1][j] && pos[i] == pos[i + 1]) {
        good = false;
        break;
      }
    }
    if (!good) {
      res++;
      continue;
    }
    pos[0] = 0;
    for (int i = (1), _b = (n - 1); i <= _b; i++) {
      if (pos[i] != i) {
        if (s[i][j] == s[i - 1][j])
          pos[i] = pos[i - 1];
        else
          pos[i] = i;
      }
    }
  }
  return res;
}
int main() {
  scanf("%d %d ", &n, &m);
  for (int i = 0, _n = (n); i < _n; i++) scanf(" %s ", s[i]);
  printf("%d\n", solve());
  return 0;
}
