#include <bits/stdc++.h>
using namespace std;
int get() {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && (c != '-'))
    ;
  bool flag = (c == '-');
  if (flag) c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return flag ? -x : x;
}
void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[10];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
char c[100][100];
bool flag[100];
int main() {
  int n = get(), m = get();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      while (c[i][j] = getchar(), c[i][j] < 'a' || c[i][j] > 'z')
        ;
  int ans = 0;
  memset(flag, 0, sizeof(flag));
  for (int j = 0; j < m; j++) {
    bool OK = true;
    for (int i = 1; OK && i < n; i++)
      if (!flag[i] && c[i][j] < c[i - 1][j]) OK = false;
    if (!OK)
      ans++;
    else
      for (int i = 1; i < n; i++) flag[i] = flag[i] || (c[i][j] > c[i - 1][j]);
  }
  output(ans);
  return 0;
}
