#include <bits/stdc++.h>
using namespace std;
const int N = 1e2;
string s[N];
bool ok[N];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    bool foo = false;
    for (int j = 1; j < n; j++) {
      if (!ok[j] && s[j][i] < s[j - 1][i]) foo = 1;
    }
    if (foo)
      ans++;
    else {
      for (int j = 1; j < n; j++) {
        if (s[j][i] > s[j - 1][i]) ok[j] = 1;
      }
    }
  }
  cout << ans;
  return 0;
}
