#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
using namespace std;
int main(void) {
  char in[101][101];
  char ans[101][101];
  int n, m;
  int cnt;
  int i, j, k;
  while (cin >> n >> m) {
    getchar();
    memset(ans, '\0', sizeof(ans));
    for (i = 0; i < n; i++) {
      gets(in[i]);
    }
    cnt = 0;
    int ind = 0;
    for (i = 0; i < m; i++) {
      bool ch = false;
      for (j = 1; j < n; j++) {
        ans[j][ind] = in[j][i];
        ans[j - 1][ind] = in[j - 1][i];
        ans[j][ind + 1] = '\0';
        ans[j - 1][ind + 1] = '\0';
        if (strcmp(ans[j], ans[j - 1]) < 0) {
          ch = true;
          break;
        }
      }
      if (ch == false) {
        ind++;
      }
    }
    cout << m - ind << endl;
  }
  return 0;
}
