#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 3;
char c[maxn][maxn];
string s[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> c[i][j];
  int ans = 0;
  for (int j = 1; j <= m; j++) {
    bool yes = false;
    for (int i = 2; i <= n; i++) {
      if (s[i] > s[i - 1]) continue;
      if (s[i] == s[i - 1] && c[i][j] >= c[i - 1][j]) continue;
      ans++;
      yes = true;
      break;
    }
    if (yes) continue;
    for (int l = 1; l <= n; l++) s[l] += c[l][j];
  }
  cout << ans << endl;
  return 0;
}
