#include <bits/stdc++.h>
using namespace std;
string s[111];
string t[111];
int id[111];
bool cmp(int u, int v) {
  if (t[u] == t[v]) return u < v;
  return t[u] < t[v];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      t[i] += s[i][j];
      id[i] = i;
    }
    sort(id, id + n, cmp);
    int flag = 0;
    for (int i = 0; i < n; i++)
      if (id[i] != i) flag = 1;
    if (flag) {
      for (int i = 0; i < n; i++) t[i].erase(--t[i].end());
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
