#include <bits/stdc++.h>
using namespace std;
int n, m, rem = 0;
char table[101][101];
int check[101];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> table[i];
    check[i] = i + 1;
  }
  int *checkend = check + n - 1, *ptr, *prevend;
  for (int i = 0; i < m; ++i) {
    for (ptr = check; table[*ptr][i] >= table[(*ptr) - 1][i] && ptr != checkend;
         ++ptr)
      if (table[*ptr][i] != table[(*ptr) - 1][i]) *ptr = -*ptr;
    if (ptr == checkend) {
      prevend = checkend;
      checkend = check;
      for (ptr = check; ptr != prevend; ++ptr)
        if (*ptr > 0) *(checkend++) = *ptr;
    } else {
      ++rem;
      while (--ptr >= check)
        if (*ptr < 0) *ptr = -*ptr;
    }
  }
  cout << rem << endl;
  return 0;
}
