#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
char a[maxn][maxn];
int n, m;
int qu[maxn];
int need[maxn];
vector<int> tmp;
void solve() {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    need[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    tmp.clear();
    for (int j = 0; j < n - 1; j++) {
      if (need[j] == 0) continue;
      if (a[j][i] < a[j + 1][i]) {
        need[j] = 0;
        tmp.push_back(j);
      } else if (a[j][i] > a[j + 1][i]) {
        ans++;
        for (int k = 0; k < tmp.size(); k++) {
          need[tmp[k]] = 1;
        }
        break;
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%s", a[i]);
    }
    solve();
  }
  return 0;
}
