#include <bits/stdc++.h>
using namespace std;
vector<string> v;
string s;
bool f[1000];
int main() {
  int ch = 10000;
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    v.push_back(s);
  }
  while (ch--) {
    for (int i = 0; i < v.size() - 1; ++i) {
      string s1 = v[i], s2 = v[i + 1];
      for (int j = 0; j < m; ++j) {
        if (f[j]) continue;
        if (s2[j] > s1[j])
          break;
        else if (s2[j] < s1[j]) {
          f[j] = 1;
        }
      }
    }
  }
  for (int i = 0; i < 105; ++i) ans += f[i];
  cout << ans;
  return 0;
}
