#include <bits/stdc++.h>
using namespace std;
const double kEps = 10e-8;
const int kMax = 105;
const int kInf = 1 << 30;
char t[kMax][kMax];
char b[kMax][kMax];
void printBuckets(int n, int m) {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", b[i][j]);
    }
    printf("\n");
  }
  printf("\n");
}
int main(int argc, char **argv) {
  int n, m;
  scanf("%d %d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      t[i + 1][j + 1] = getchar();
    }
    getchar();
  }
  int ans = 0;
  int bucket = 1;
  for (int j = 1; j <= m; j++) {
    bool ok = true;
    for (int i = 1; i <= n && ok;) {
      int k;
      for (k = i + 1; k <= n && b[k][j] == b[i][j]; k++)
        ;
      bool sorted = true;
      for (int l = i + 1; l < k && sorted; l++) {
        sorted &= t[l][j] >= t[l - 1][j];
      }
      if (!sorted) {
        ok = false;
      }
      i = k;
    }
    if (!ok) {
      ans++;
      continue;
    }
    for (int i = 1; i <= n;) {
      int k;
      for (k = i + 1; k <= n && b[k][j] == b[i][j]; k++)
        ;
      for (int p = i; p < k;) {
        int q;
        for (q = p + 1; q < k && t[q][j] == t[p][j]; q++)
          ;
        for (int r = p; r < q; r++) {
          for (int c = j; c <= m; c++) {
            b[r][c] = bucket;
          }
        }
        bucket++;
        p = q;
      }
      i = k;
    }
  }
  cout << ans << endl;
  return EXIT_SUCCESS;
}
