#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, n, m, flg, r, c, rr[1000], cc[1000], fst;
  char inp[101][101], ch;
  cin >> r >> c;
  for (i = 0; i < r; i++) {
    getchar();
    for (j = 0; j < c; j++) inp[i][j] = getchar();
  }
  fst = -1;
  for (j = 0; j < c; j++) {
    flg = 1;
    for (i = 1; i < r; i++) {
      if (inp[i][j] < inp[i - 1][j]) flg = 0;
    }
    if (flg) {
      fst = j;
      break;
    }
  }
  if (fst == -1) {
    cout << c << endl;
    return 0;
  }
  memset(cc, 1, sizeof(cc));
  cc[fst] = 0;
  for (j = fst + 1; j < c; j++) {
    flg = 0;
    for (i = 1; i < r; i++) {
      flg = 0;
      if (inp[i][j] < inp[i - 1][j]) {
        for (k = fst; k <= j; k++) {
          if (cc[k] && k != j) continue;
          if (inp[i][k] == inp[i - 1][k])
            continue;
          else {
            if (inp[i][k] < inp[i - 1][k])
              flg = 1;
            else
              flg = 2;
          }
          if (flg) break;
        }
      }
      if (flg == 1) break;
    }
    if (flg != 1) cc[j] = 0;
  }
  long long cnt = 0;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
    }
  }
  for (i = 0; i < c; i++)
    if (cc[i]) cnt++;
  cout << cnt << endl;
  return 0;
}
