#include <bits/stdc++.h>
using namespace std;
int sel[1021];
int diff[1012];
string cuvinte[1024];
int main() {
  int n, m;
  string first, second;
  cin >> n >> m;
  int count = 0;
  for (int k = 0; k < n; ++k) {
    cin >> cuvinte[k];
  }
  for (int k = 0; k < m; ++k) {
    int del = 0;
    for (int i = 1; i < n; ++i) {
      if (cuvinte[i][k] < cuvinte[i - 1][k] && diff[i] == 0) del = 1;
    }
    if (del == 1) {
      count++;
      continue;
    }
    for (int i = 1; i < n; ++i)
      if (cuvinte[i][k] > cuvinte[i - 1][k]) diff[i] = 1;
  }
  cout << count << endl;
  return 0;
}
