#include <bits/stdc++.h>
using namespace std;
long long int GCD(long long int a, long long int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> v1(n);
  vector<string> v2(n);
  for (int i = 0; i < n; i++) cin >> v1[i];
  int count = 0;
  for (int j = 0; j < m; j++) {
    int index = 0;
    for (int i = 0; i < n; i++) {
      v2[i].push_back(v1[i][j]);
      if (i != 0 && (v2[i] < v2[i - 1])) {
        count++;
        index = i + 1;
        break;
      }
    }
    for (int i = 0; i < index; i++) v2[i].pop_back();
  }
  cout << count << endl;
}
int main() { solve(); }
