#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  v.resize(n);
  for (long long i = 0; i < (n); ++i) cin >> v[i];
  long long rmd = 0;
  while (1) {
    bool gn = 0;
    for (long long i = 0; i < (n - 1); ++i) {
      for (long long j = 0; j < (m); ++j) {
        if (v[i][j] < v[i + 1][j]) break;
        if (v[i][j] > v[i + 1][j]) {
          ++rmd;
          gn = 1;
          for (long long k = 0; k < (n); ++k) v[k][j] = 'a';
          break;
        }
      }
    }
    if (!gn) break;
  }
  cout << rmd << endl;
  return 0;
}
