#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
inline long long read() {
  int X = 0;
  bool flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    X = (X << 1) + (X << 3) + ch - '0';
    ch = getchar();
  }
  if (flag) return X;
  return ~(X - 1);
}
inline void write(long long x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
long long res(long long x) {
  long long ans = 1;
  for (long long i = 1; i <= x; ++i) {
    ans *= i;
  }
  return ans;
}
char a[200][200];
bool b[200] = {false};
int c[200];
int main() {
  int n = read(), m = read();
  memset(c, 0, sizeof(c));
  for (int i = 0; i < n; ++i) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < m; ++i) {
    int flag = 0;
    for (int j = 0; j < n - 1; ++j) {
      if (c[j] == 1) continue;
      if (a[j + 1][i] < a[j][i]) flag = 1;
    }
    if (flag == 1)
      b[i] = true;
    else {
      for (int j = 0; j < n - 1; ++j) {
        if (a[j + 1][i] > a[j][i]) c[j] = 1;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < m; ++i) {
    if (b[i] == true) res++;
  }
  write(res);
  return 0;
}
