#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, len;
  scanf("%d", &n);
  scanf("%d", &len);
  vector<string> s(n);
  int answer = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int col = 0; col < (int)s[0].length(); 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 str;
        for (int j = 0; j < s[i].length(); j++) {
          if (j != col) {
            str += s[i][j];
          }
        }
        s[i] = str;
      }
      col--;
    }
  }
  cout << answer << endl;
  return 0;
}
