#include <bits/stdc++.h>
using namespace std;
char x[100][101];
bool c[100];
int main() {
  cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> x[i];
  int res = 0;
  for (int i = 0; i < m; ++i) {
    bool did = false;
    for (int j = 1; j < n && !did; ++j) {
      for (int k = 0; k < m && !did; ++k) {
        if (c[k]) continue;
        if (x[j][k] < x[j - 1][k]) {
          did = c[k] = true;
          res++;
        } else if (x[j][k] > x[j - 1][k])
          break;
      }
    }
  }
  cout << res << "\n";
  return 0;
}
