#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a;
  for (int i = 0; i < n; i++) {
    string n;
    cin >> n;
    a.push_back(n);
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int fa = 0;
  int ind = -1;
  for (int i = 0; i < m; i++) {
    bool found = false;
    for (int j = 0; j < n - 1; j++) {
      if (a[j + 1][i] < a[j][i]) break;
      if (j == n - 2) found = true;
    }
    if (!found)
      fa++;
    else {
      ind = i;
      break;
    }
  }
  if (fa == m) {
    cout << fa;
    return 0;
  }
  vector<pair<int, int> > rem;
  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1][ind] == a[i][ind]) rem.push_back(make_pair(i, i + 1));
  }
  for (int i = ind + 1; i < m; i++) {
    bool found2 = false;
    vector<int> solved;
    for (int j = 0; j < n - 1; j++) {
      bool found = false;
      int ind2 = -1;
      for (int k = 0; k < rem.size(); k++) {
        if (rem[k].first == j) {
          found = true;
          ind2 = k;
          break;
        }
      }
      if (found) {
        if (a[j + 1][i] < a[j][i])
          break;
        else if (a[j + 1][i] > a[j][i])
          solved.push_back(ind2);
      }
      if (j == n - 2) found2 = true;
    }
    if (!found2)
      fa++;
    else {
      sort(solved.begin(), solved.end());
      int err = 0;
      for (int i = 0; i < solved.size(); i++) {
        rem.erase(rem.begin() + (solved[i] - err));
        err++;
      }
    }
  }
  cout << fa;
}
