#include <bits/stdc++.h>
using namespace std;
int mark[100005];
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  string a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  string s[m];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) s[i] += a[j][i];
  int cnt = 0;
  vector<int> v;
  bool k;
  k = 0;
  for (int i = 0; i < m; i++) {
    k = 0;
    for (int j = 0; j < n - 1; j++)
      if (s[i][j] > s[i][j + 1]) {
        if (mark[j] == 0) {
          cnt++;
          k = 1;
          break;
        }
      } else if (s[i][j] < s[i][j + 1])
        v.push_back(j);
    if (k == 0)
      for (int j = 0; j < v.size(); j++) mark[v[j]] = 1;
    v.clear();
  }
  cout << cnt;
  return 0;
}
