#include <bits/stdc++.h>
using namespace std;
const long long INF64 = 1e18;
const long long INF = 1e9;
const double PI = acos(-1);
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
inline long long mul(long long a, long long b) {
  return (long long)((long long)a * b % 1000000007);
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long binExpo(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
long long spf[200005];
bool isPrime[200005];
void sieve() {
  spf[2] = 1;
  spf[3] = 1;
  for (long long i = 2; i * i < 200005; i++) {
    if (isPrime[i] == false) {
      for (long long j = i * i; j < 200005; j += i) {
        if (spf[j] == 0) spf[j] = i;
        isPrime[j] = true;
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (__typeof((n - 1)) i = (0); i <= (n - 1); i++) {
    cin >> s[i];
  }
  int cnt = 0;
  for (int col = 0; col < (int)s[0].length(); col++) {
    bool is_sorted = true;
    for (__typeof((n - 2)) i = (0); i <= (n - 2); i++) {
      if (s[i].substr(0, col + 1) > s[i + 1].substr(0, col + 1)) {
        is_sorted = false;
      }
    }
    if (!is_sorted) {
      cnt++;
      for (__typeof((n - 1)) i = (0); i <= (n - 1); i++) {
        string new_string;
        for (__typeof((s[i].length() - 1)) j = (0); j <= (s[i].length() - 1);
             j++) {
          if (j != col) new_string += s[i][j];
        }
        s[i] = new_string;
      }
      col--;
    }
  }
  cout << cnt << '\n';
  return 0;
}
