#include <bits/stdc++.h>
using namespace std;
int n, m, label[1010];
char s[1002][1010];
int main() {
  cin >> n >> m;
  for (int i = 0; i < (n); i++) cin >> s[i];
  int cnt = 0, cur = 0, stramp = 1;
  memset(label, 0, sizeof(label));
  ;
  while (cur < m) {
    bool del = 0;
    for (int i = 0; i < n;) {
      int j;
      for (j = i + 1; j < n && label[i] == label[j]; j++)
        ;
      for (int k = i + 1; k < j; k++)
        if (s[k][cur] < s[k - 1][cur]) {
          del = 1;
          goto DEL;
        }
      i = j;
    }
    for (int i = 0; i < n;) {
      int j;
      for (j = i + 1; j < n && label[i] == label[j]; j++)
        ;
      label[i] = ++stramp;
      for (int k = i + 1; k < j; k++) {
        if (s[k][cur] != s[k - 1][cur]) stramp++;
        label[k] = stramp;
      }
      i = j;
    }
  DEL:;
    if (del) cnt++;
    cur++;
  }
  cout << cnt << endl;
}
