#include <bits/stdc++.h>
using namespace std;
void yala_bena() {
  cin.tie(0);
  std::ios::sync_with_stdio(0);
}
const int m_r = 199999;
double pii = 3.1415926536;
bool traffic(double g, double r, double target) {
  double start = 1;
  double endd = g;
  while (endd <= 1000) {
    if (target >= start && target <= endd) return 1;
    start = endd + r + 1;
    endd = start + g - 1;
  }
  return 0;
}
int main() {
  yala_bena();
  vector<string> v, v1;
  int n, m;
  cin >> n >> m;
  string s;
  for (int i = 0; i < n; i++) cin >> s, v.push_back(s);
  v1 = v;
  long long sum = 0;
  sort(v.begin(), v.end());
  for (int i = 0; i < v[0].size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      if (v[j][i] != v1[j][i]) {
        sum++;
        for (int h = 0; h < v.size(); h++) {
          v[h][i] = (char)1;
          v1[h][i] = v[h][i];
        }
        sort(v.begin(), v.end());
        break;
      }
    }
  }
  cout << sum << endl;
}
