#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  string s;
  vector<string> x;
  vector<pair<char, int>> y[101];
  for (int i = 0; i < n; i++) {
    cin >> s;
    x.push_back(s);
  }
  for (int j = 0; j < x.size(); j++) {
    for (int i = 0; i < x[j].length(); i++) {
      y[i].push_back(make_pair(x[j][i], j));
    }
  }
  vector<string> ss;
  for (int i = 0; i < n; i++) {
    string temp;
    ss.push_back(temp);
  }
  for (int k = 0; k < m; k++) {
    int ff = 0;
    vector<string> sss;
    for (int i = 0; i < y[k].size(); i++) {
      sss.push_back(ss[i] + y[k][i].first);
    }
    for (int i = 1; i < sss.size(); i++) {
      if (sss[i - 1] > sss[i]) {
        ff = 1;
        break;
      }
    }
    if (ff == 0) {
      for (int i = 0; i < y[k].size(); i++) {
        ss[i] = ss[i] + y[k][i].first;
      }
    }
  }
  cout << (m - ss[0].size()) << endl;
  return 0;
}
