#include <bits/stdc++.h>
using namespace std;
char s[150][150];
int n, m, flg[150], now[150];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  int ans = 0;
  memset(now, 0, sizeof(now));
  for (int i = 0; i < m; i++) {
    memset(flg, 0, sizeof(flg));
    int wh = 1;
    for (int j = 0; j < n - 1 && wh; j++) {
      if (now[j]) continue;
      if (s[j][i] > s[j + 1][i]) {
        wh = 0;
        ans++;
        break;
      } else if (s[j][i] < s[j + 1][i]) {
        flg[j] = 1;
      }
    }
    if (wh)
      for (int j = 0; j < n; j++)
        if (flg[j]) now[j] = 1;
  }
  cout << ans << endl;
}
