#include <bits/stdc++.h>
using namespace std;
const double pi = 4 * atan(1.0);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
inline int r() {
  char ch;
  bool flag = false;
  int a = 0;
  while (!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-')))
    ;
  if (ch != '-') {
    a *= 10;
    a += ch - '0';
  } else {
    flag = true;
  }
  while (((ch = getchar()) >= '0') && (ch <= '9')) {
    a *= 10;
    a += ch - '0';
  }
  if (flag) {
    a = -a;
  }
  return a;
}
char w[110][110];
int islex[110];
int tmprows[110];
int n, m;
int neederase;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", w[i]);
  }
  memset(islex, 0, sizeof islex);
  int cnt = 0;
  neederase = 0;
  for (int i = 0; i < m; ++i) {
    memset(tmprows, 0, sizeof tmprows);
    cnt = 0;
    for (int j = 0; j < n - 1; ++j) {
      if (!islex[j]) {
        if (w[j][i] < w[j + 1][i]) {
          tmprows[cnt] = j;
          ++cnt;
        } else if (w[j][i] > w[j + 1][i]) {
          cnt = 0;
          ++neederase;
          break;
        }
      }
    }
    if (cnt != 0) {
      for (int i = 0; i < cnt; ++i) {
        islex[tmprows[i]] = 1;
      }
    }
  }
  printf("%d\n", neederase);
  return 0;
}
