#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1, M = N;
const int mod = 1000000007;
map<long long, int> mp;
map<int, char> mp1;
vector<long long> v;
vector<pair<long long, long long> > vi;
vector<long long>::iterator it;
int ans, idx;
long long lps[N];
void faliurefunction(string &s, long long n) {
  long long i = 0, j = -1;
  lps[i] = j;
  while (i < n) {
    while (j >= 0 && s[i] != s[j]) j = lps[j];
    i++, j++;
    lps[i] = j;
  }
}
void kmpSearch(string &t, string &p, int n, int m) {
  int i = 0, j = 0;
  while (i < n) {
    while (j >= 0 && t[i] != p[j]) j = lps[j];
    i++;
    j++;
    if (j == m) {
      ans++;
      v.push_back(i - j + 1);
      j = lps[j];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int col = 0; col < v[0].length(); col++) {
    bool is_sorted = true;
    for (int i = 0; i < n - 1; i++) {
      if (v[i].substr(0, col + 1) > v[i + 1].substr(0, col + 1))
        is_sorted = false;
    }
    if (!is_sorted) {
      ans++;
      for (int i = 0; i < n; i++) {
        string new_string;
        for (int j = 0; j < v[i].length(); j++) {
          if (j != col) new_string += v[i][j];
        }
        v[i] = new_string;
      }
      col--;
    }
  }
  cout << ans;
  return 0;
}
