#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "[";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int n, m;
int main() {
  cin >> n >> m;
  vector<string> s(n);
  vector<int> f(n);
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    int ff = 0;
    for (int j = 0; j < (int)(n - 1); j++) {
      ff |= !f[j] && s[j][i] > s[j + 1][i];
    }
    if (ff)
      ans++;
    else
      for (int j = 0; j < (int)(n - 1); j++) {
        f[j] |= s[j][i] < s[j + 1][i];
      }
  }
  cout << ans << endl;
  return 0;
}
