#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const int MAXN = 1e3 + 9;
const int MOD = (int)(1e9 + 7);
const int INF = 1e9;
string aa[111];
int done[111][111];
int n, m;
void input() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> aa[i];
}
void solve() {
  int ans = 0;
  for (int i = 0; i < m; i++) {
    bool needToDelete = 0;
    for (int j = 0; j < n - 1; j++) {
      if (done[j][j + 1] || aa[j][i] <= aa[j + 1][i])
        continue;
      else
        needToDelete = 1;
    }
    if (needToDelete) {
      ans++;
      cerr << i + 1 << endl;
      continue;
    }
    for (int j = 0; j < n - 1; j++)
      if (aa[j][i] < aa[j + 1][i]) done[j][j + 1] = 1;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  input();
  solve();
  return 0;
}
