#include <bits/stdc++.h>
using namespace std;
char b[111];
string s[111], a[111];
int n, m, ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", b);
    s[i] = b;
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) a[i] += s[i][j];
    int k = 1;
    for (; k < n; ++k)
      if (a[k] < a[k - 1]) break;
    if (k < n) {
      ++ans;
      for (int i = 0; i < n; ++i) a[i].erase((int)a[i].size() - 1, 1);
    }
  }
  printf("%d", ans);
  return 0;
}
