#include <bits/stdc++.h>
using namespace std;
void solve();
void precalc();
clock_t start;
bool doing = true;
int main() {
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  start = clock();
  int testNum = 1;
  while (t--) {
    solve();
  }
  return 0;
}
void precalc() {}
int binpow(int q, int w, int mod) {
  if (!w) return 1;
  if (w & 1) return q * binpow(q, w - 1, mod) % mod;
  return binpow(q * q % mod, w / 2, mod);
}
int mod = 1000000007;
int gcd(int q, int w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
int n, m;
string s[1005];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  vector<char> good(n - 1, false);
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    bool need = false;
    for (int j = 0; j + 1 < n; ++j) {
      if (good[j]) {
        continue;
      }
      if (s[j][i] > s[j + 1][i]) {
        need = true;
      }
    }
    if (need) {
      ++ans;
    } else {
      for (int j = 0; j + 1 < n; ++j) {
        if (s[j][i] < s[j + 1][i]) {
          good[j] = true;
        }
      }
    }
  }
  cout << ans << "\n";
}
