#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int N, M, out = 0;
  cin >> N >> M;
  vector<string> str(N);
  for (auto &second : str) cin >> second;
  for (int i = 0; i < (int)str[0].size(); i++) {
    bool flag = true;
    for (int k = 0; k < N - 1; k++)
      if (str[k].substr(0, i + 1) > str[k + 1].substr(0, i + 1)) flag = false;
    if (!flag) {
      out++;
      for (int k = 0; k < N; k++) {
        string second = "";
        for (int j = 0; j < (int)str[k].size(); j++)
          if (j != i) second += str[k][j];
        str[k] = second;
      }
      i--;
    }
  }
  cout << out << '\n';
}
