#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<string> a;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    a.push_back(s);
  }
  bool removed[m];
  for (int i = 0; i < m; ++i) removed[i] = false;
  bool strictlySmaller[n - 1];
  for (int i = 0; i < n - 1; ++i) strictlySmaller[i] = false;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      bool flag = false;
      for (int p = 0; p < i; ++p) {
        if (!removed[p] && a[j][p] < a[j + 1][p]) {
          flag = true;
          break;
        }
      }
      if (flag) continue;
      if (a[j][i] > a[j + 1][i]) removed[i] = true;
    }
  }
  int c = 0;
  for (int i = 0; i < m; ++i) {
    if (removed[i]) c++;
  }
  cout << c << '\n';
  return 0;
}
