#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<char> > a(n, vector<char>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  long long ans = 0;
  vector<int> frow(n, -1);
  vector<int> row(n, -1);
  for (int j = 0; j < m; j++) {
    bool rcheck = false;
    row = frow;
    for (int i = 0; i < n - 1; i++) {
      if (row[i] == 1) continue;
      if (a[i][j] > a[i + 1][j]) {
        rcheck = true;
      } else if (a[i][j] == a[i + 1][j])
        row[i] = 0;
      else
        row[i] = 1;
    }
    row[n - 1] = 1;
    if (rcheck) {
      ++ans;
      continue;
    }
    frow = row;
    bool check = true;
    for (int i = 0; i < n - 1; i++) {
      if (row[i] == 0) {
        check = false;
      }
    }
    if (check) break;
  }
  cout << ans << endl;
  return 0;
}
