#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double Pi = acos(-1);
using namespace std;
int debug = 01;
int main() {
  int a, b;
  cin >> a >> b;
  string g[a], s[a];
  for (int i = 0; i < a; i++) cin >> g[i];
  int c = 0;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < a; j++) s[j] += g[j][i];
    for (int j = 1; j < a; j++)
      if (s[j] < s[j - 1]) {
        c++;
        for (int k = 0; k < a; k++) s[k].erase(s[k].size() - 1);
        break;
      }
  }
  cout << c;
}
