#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
bool done[1005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int r = 0;
  for (int j = 0; j < m; j++) {
    bool good = true;
    for (int i = 1; i < n; i++) {
      if (done[i]) continue;
      if (a[i][j] < a[i - 1][j]) {
        good = false;
        break;
      }
    }
    if (good) {
      for (int i = 1; i < n; i++) {
        if (a[i][j] > a[i - 1][j]) done[i] = true;
      }
    } else {
      r++;
    }
  }
  cout << r << endl;
  return 0;
}
