#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T GCD(T a, T b) {
  return b ? GCD(b, a % b) : a;
}
template <class T>
inline T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return a * (b / GCD(a, b));
}
template <class T>
inline T POW1(T a, T b, T m) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > m) x %= m;
    }
    y = (y * y);
    if (y > m) y %= m;
    b /= 2;
  }
  return x;
}
template <class T>
inline T INV(T n, T m) {
  return POW1(n, m - 2, m);
}
template <class T>
inline T SUB(T a, T b, T m) {
  return (a % m - b % m + m) % m;
}
template <class T>
inline T ADD(T a, T b, T m) {
  return (a % m + b % m) % m;
}
template <class T>
inline T MUL(T a, T b, T m) {
  return (a % m * b % m) % m;
}
template <class T>
inline T DIV(T a, T b, T m) {
  return (a % m * (INV(b, m)) % m) % m;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<string> board(n);
  for (long long int i = 0; i < n; i++) cin >> board[i];
  long long int ans = 0;
  vector<bool> ign(m, false);
  bool flg = false;
  while (!flg) {
    flg = true;
    for (long long int i = 1; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        if (!ign[j]) {
          if (board[i][j] > board[i - 1][j]) {
            break;
          } else if (board[i][j] == board[i - 1][j]) {
            continue;
          } else {
            ign[j] = true;
            ans++;
            flg = false;
            break;
          }
        }
      }
      if (!flg) break;
    }
  }
  cout << ans << endl;
  return 0;
}
