#include <bits/stdc++.h>
using namespace std;
string s[105], t[105], c[105];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int j = 0; j < m; j++) {
    int f = 1;
    for (int i = 0; i < n; i++) t[i] += s[i][j];
    for (int i = 1; i < n; i++)
      if (t[i] < t[i - 1]) f = 0;
    if (f) {
      for (int i = 0; i < n; i++) c[i] = t[i];
    } else {
      for (int i = 0; i < n; i++) t[i] = c[i];
    }
  }
  printf("%d", s[0].size() - c[0].size());
  return 0;
}
