#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VB = vector<bool>;
using VD = vector<long double>;
using VC = vector<char>;
using VS = vector<string>;
using V2I = vector<VI>;
using V3I = vector<V2I>;
const ll mod{(ll)1e9 + 7};
const long double pi = 2 * acos(0.0);
void solve() {
  ll n, m;
  cin >> n >> m;
  VS vec(n), ans(n);
  for (string &x : vec) cin >> x;
  ll ct{};
  for (ll i{}; i < m; i++) {
    for (ll j{}; j < n; j++) ans[j] += vec[j][i];
    VS tem{ans};
    sort(tem.begin(), tem.end());
    if (tem != ans) {
      for (ll j{}; j < n; j++) ans[j].pop_back();
      ct++;
    }
  }
  cout << ct;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
