#include <bits/stdc++.h>
using namespace std;
long long MOD = int(1e9) + 7;
inline int inp() {
  register int n = 0, s = 1, c = getchar();
  if (c == '-') s = -1;
  while (c < 48) c = getchar();
  while (c > 47) n = (n << 3) + (n << 1) + c - '0', c = getchar();
  return n * s;
}
inline void writeInt(long long n) {
  long long N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar('0');
    putchar('\n');
    return;
  }
  while ((rev % 10) == 0) {
    count++;
    rev /= 10;
  }
  rev = 0;
  while (N != 0) {
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) {
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
}
const int N = 1000 * 100 + 5;
int debug = 1;
string s[1005];
int les[1005];
int ans = 0;
int main() {
  ios::sync_with_stdio(false);
  int i, j, n, m, t;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s[i];
  for (j = 0; j < m; j++) {
    int ch = 0;
    for (i = 1; i < n; i++) {
      if (les[i]) continue;
      if (s[i][j] < s[i - 1][j]) ch = 1;
    }
    if (ch) {
      ans++;
      continue;
    }
    for (i = 1; i < n; i++) {
      if (s[i][j] > s[i - 1][j]) les[i] = 1;
    }
  }
  cout << ans << endl;
  cin >> i;
}
