#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 100;
long long int inf = 1e17 + 100;
bool mark[N];
string second[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> second[i];
    mark[i] = true;
  }
  for (int i = 0; i < m; i++) {
    bool fl = false;
    for (int j = 0; j < n - 1; j++) {
      if (mark[j] && second[j][i] > second[j + 1][i]) {
        fl = true;
      }
    }
    ans += fl;
    for (int j = 0; j < n - 1; j++) {
      if (mark[j] && (fl || second[j][i] == second[j + 1][i]))
        mark[j] = true;
      else
        mark[j] = false;
    }
  }
  cout << ans << endl;
  return 0;
}
