#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char a[105][105];
bool vis[105];
inline void check(int j) {
  int i, ok = true;
  for (i = 1; i < n; ++i) {
    if (vis[i]) continue;
    if (a[i][j] > a[i + 1][j]) ok = false;
  }
  if (!ok) {
    ++ans;
    return;
  }
  for (i = 1; i < n; ++i) {
    if (vis[i]) continue;
    if (a[i][j] < a[i + 1][j]) vis[i] = true;
  }
  return;
}
int main(void) {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%s", a[i] + 1);
  for (i = 1; i <= m; ++i) check(i);
  printf("%d\n", ans);
  return 0;
}
