#include <bits/stdc++.h>
using namespace std;
string a[100005];
int b[2][100005], n, m, ans, ok;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[0][i] = 0;
  }
  ok = 1;
  ans = 0;
  for (int j = 0; j < m; j++) {
    ok = !ok;
    for (int i = 2; i <= n; i++) {
      if (b[ok][i])
        b[!ok][i] = 1;
      else {
        if (a[i - 1][j] > a[i][j]) {
          ok = !ok;
          ans++;
          break;
        } else if (a[i - 1][j] == a[i][j])
          b[!ok][i] = 0;
        else
          b[!ok][i] = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
