#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) cin >> s[i];
  int answer = 0;
  for (int col = 0; col < (int)s[0].size(); ++col) {
    bool is_sorted = true;
    for (int i = 0; i < n - 1; ++i) {
      if (s[i].substr(0, col + 1) > s[i + 1].substr(0, col + 1)) {
        is_sorted = false;
      }
    }
    if (!is_sorted) {
      ++answer;
      for (int i = 0; i < n; ++i) {
        string new_string;
        for (int j = 0; j < (int)s[i].size(); ++j) {
          if (j != col) {
            new_string += s[i][j];
          }
        }
        s[i] = new_string;
      }
      --col;
    }
  }
  cout << answer << endl;
  return 0;
}
