#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 10;
const long long inf = 1e9;
char ch[MAX_N][MAX_N];
int n, m;
bool mark[MAX_N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> ch[i][j];
  int ans = 0;
  while (1) {
    bool sw = false;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = 1; k <= m; k++) {
          if (mark[k] == true) continue;
          if (ch[i][k] < ch[j][k]) break;
          if (ch[i][k] > ch[j][k]) {
            ans++;
            sw = true;
            mark[k] = true;
            break;
          }
        }
        if (sw) break;
      }
      if (sw) break;
    }
    if (!sw) {
      cout << ans;
      return 0;
    }
  }
}
