#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 9;
int n, m, o = 0;
string t[N];
bool b[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> t[i];
  for (int i = 0; i < m; i++) {
    bool c = false;
    for (int j = 1; j < n; j++)
      if ((int)t[j][i] < (int)t[j - 1][i] && !b[j]) {
        o++;
        c = true;
        break;
      }
    if (c) continue;
    for (int j = 1; j < n; j++)
      if (t[j][i] > t[j - 1][i]) b[j] = true;
  }
  cout << o << "\n";
}
