#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
int n, m;
string s[N], ans[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<int> pos;
  for (int j = 0; j < m; j++) {
    int cnt = 0;
    for (int i = 1; i < n; i++)
      cnt += (ans[i - 1] + "" + s[i - 1][j] <= ans[i] + "" + s[i][j]);
    if (cnt == n - 1) {
      for (int i = 0; i < n; i++) ans[i] += s[i][j];
    }
  }
  cout << m - ans[0].size() << "\n";
}
