#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long tc = 1;
  while (tc--) {
    long long n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (auto &x : a) cin >> x;
    long long ans = 0;
    vector<long long> strict(n, 1);
    for (long long j = 0; j < m; j++) {
      char ch = a[0][j];
      bool flag = false;
      vector<long long> temp_strict = strict;
      for (long long i = 1; i < n; i++) {
        if (temp_strict[i]) {
          if (a[i][j] < ch) {
            flag = true;
            break;
          } else if (a[i][j] > ch) {
            temp_strict[i] = 0;
          }
        }
        ch = a[i][j];
      }
      if (flag) {
        ans++;
      } else
        strict = temp_strict;
    }
    cout << ans;
  }
  return 0;
}
