#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  char a[n][m];
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  vector<long long> c(m, true);
  long long ans = 0;
  for (long long j = 0; j < m; ++j) {
    bool access = true;
    for (long long i = 1; i < n; ++i) {
      for (long long k = 0; k <= j; ++k) {
        if (c[k]) {
          if (a[i - 1][k] > a[i][k]) {
            access = false;
          }
          if (a[i - 1][k] < a[i][k]) {
            break;
          }
        }
      }
    }
    c[j] = access;
    ans += !access;
  }
  cout << ans;
}
