#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > v;
char a[1007][1007];
int b[1007];
int bb[1007];
int main() {
  int m, p;
  scanf("%d %d", &m, &p);
  int ans = 0;
  int i, j;
  for (i = 0; i < m; i++) scanf("%s", a[i]);
  for (i = 0; i < m; i++) b[i] = 1;
  for (i = 0; i < p; i++) {
    for (j = 0; j < m; j++)
      v.push_back(make_pair(make_pair(b[j], a[j][i] - 'a'), j));
    sort(v.begin(), v.end());
    int tem = 0;
    j = 0;
    while (j < v.size())
      if (j == 0 || v[j].first != v[j - 1].first)
        bb[v[j].second] = tem + 1, tem++, j++;
      else
        bb[v[j].second] = tem, j++;
    int lt = 0;
    for (j = 1; j < m; j++)
      if (bb[j] < bb[j - 1]) {
        lt = 1;
        break;
      }
    if (!lt) {
      for (j = 0; j < m; j++) b[j] = bb[j];
    } else
      ans++;
    v.clear();
  }
  printf("%d\n", ans);
  return 0;
}
