#include <bits/stdc++.h>
using namespace std;
string rows[1000];
bool solved[1000];
int n, m, result;
int main() {
  cin.sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> rows[i];
  for (int j = 0; j < m; j++) {
    bool toremove = false;
    for (int i = 0; i < n - 1; i++)
      if (!solved[i] && rows[i][j] > rows[i + 1][j]) toremove = true;
    if (toremove)
      result++;
    else
      for (int i = 0; i < n - 1; i++)
        if (rows[i][j] < rows[i + 1][j]) solved[i] = true;
  }
  cout << result << '\n';
  return 0;
}
