#include <bits/stdc++.h>
using namespace std;
char s[200][200];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  vector<int> num(n, 0);
  int res = 0;
  for (int i = 0; i < m; ++i) {
    int j = 1;
    while (j < n &&
           make_pair(num[j - 1], s[j - 1][i]) <= make_pair(num[j], s[j][i])) {
      ++j;
    }
    if (j < n) {
      ++res;
    } else {
      vector<int> new_num(n, 0);
      for (int j = 1; j < n; ++j) {
        new_num[j] = new_num[j - 1];
        if (make_pair(num[j - 1], s[j - 1][i]) < make_pair(num[j], s[j][i])) {
          ++new_num[j];
        }
      }
      num.swap(new_num);
    }
  }
  printf("%d\n", res);
  return 0;
}
