#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return (a > b); }
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main(void) {
  int n, m;
  cin >> n >> m;
  string s[n];
  int c = 0, i, j, k;
  for (i = 0; i < n; ++i) cin >> s[i];
  bool b[100] = {0};
  for (i = 0; i < m; ++i) {
    for (j = 1; j < n; ++j) {
      if (s[j][i] < s[j - 1][i]) {
        b[i] = 1;
        for (k = 0; k < i; ++k) {
          if (!b[k] && s[j][k] > s[j - 1][k]) {
            b[i] = 0;
            break;
          }
        }
        if (b[i]) break;
      }
    }
  }
  for (i = 0; i < m; ++i) {
    if (b[i]) c++;
  }
  cout << c;
  return 0;
}
