#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9 + 7;
const int N = 100 + 5;
string s[N];
int n, m;
void remCol(int col) {
  for (int i = 0; i < n; ++i) s[i].erase(s[i].begin() + col);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  int ans = 0;
  while (true) {
    bool remove = false;
    for (int i = 0; i < n - 1 && !remove; ++i) {
      for (int j = 0; j < (int)((s[i]).size()) && !remove; ++j) {
        if (s[i][j] < s[i + 1][j]) {
          break;
        } else if (s[i][j] > s[i + 1][j]) {
          remove = true;
          ++ans;
          remCol(j);
        }
      }
    }
    if (!remove) break;
  }
  cout << ans;
}
