#include <bits/stdc++.h>
using namespace std;
int n, m;
char temp[101][105];
void judge(vector<int> &t, char *s1, char *s2) {
  vector<int>::iterator vit = t.begin();
  while (vit != t.end()) {
    if (s1[*vit] < s2[*vit])
      return;
    else if (s1[*vit] == s2[*vit])
      vit++;
    else {
      vit = t.erase(vit);
    }
  }
}
int main() {
  vector<int> iset;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    iset.push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%s", temp[i]);
  }
  vector<int>::iterator vit;
  int t;
  do {
    t = iset.size();
    for (int i = 1; i < n; ++i) {
      judge(iset, temp[i - 1], temp[i]);
    }
  } while (t != iset.size());
  cout << m - iset.size() << endl;
  return 0;
}
