#include <bits/stdc++.h>
using namespace std;
string in[(105)];
bool good[(105)];
bool temp[(105)];
int main() {
  int R, C;
  cin >> R >> C;
  for (int i = 0; i < R; i++) cin >> in[i];
  int ans = 0;
  for (int j = 0; j < C; j++) {
    memset(temp, 0, sizeof(temp));
    bool ch = false;
    for (int i = 0; i < R - 1; i++) {
      if (good[i]) continue;
      if (in[i][j] < in[i + 1][j]) {
        temp[i] = true;
      } else if (in[i][j] > in[i + 1][j]) {
        ch = true;
        ans++;
        break;
      }
    }
    if (!ch) {
      for (int i = 0; i < R - 1; i++) good[i] |= temp[i];
    }
  }
  cout << ans << endl;
  return 0;
}
