#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const* argv[]) {
  int n, m;
  cin >> n >> m;
  char a[1000][1000];
  std::set<int> rows;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  int d[1000][1000] = {0};
  for (int i = 0; i < (n - 1); i++) {
    rows.insert(i);
    for (int j = 0; j < m; j++) {
      if (a[i][j] == a[i + 1][j]) d[i][j] = -1;
      if (a[i][j] > a[i + 1][j]) d[i][j] = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int f1, f2;
    f1 = f2 = 0;
    for (int j = 0; j < (n - 1); j++) {
      if (rows.count(j) == 0) continue;
      if (d[j][i] == -1) {
        f2 = 1;
      } else if (d[j][i] == 1)
        f1 = 1;
    }
    if (f1 == 1)
      ans++;
    else {
      for (int j = 0; j < (n - 1); j++) {
        if (d[j][i] == 0) rows.erase(j);
      }
    }
    if (f2 == 0 && f1 == 0) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
