#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
char str[1005][1005];
int cmp[1005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", str[i]);
  int ans = 0;
  for (int j = 0; j < m; ++j) {
    bool flag = true;
    for (int i = 1; i < n; ++i)
      if (str[i - 1][j] > str[i][j] and strncmp(str[i - 1], str[i], j) >= 0)
        flag = false;
    if (!flag) {
      for (int i = 0; i < n; ++i) str[i][j] = 'a';
      ans++;
    }
  }
  printf("%d\n", ans);
}
