#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  string col[m];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      col[i].push_back(s[j][i]);
    }
  }
  int rem = 0;
  map<int, int> dc;
  for (int i = 0; i < m; i++) {
    if (i == 0) {
      string ss = col[i];
      sort(ss.begin(), ss.end());
      if (ss != col[i]) {
        dc[i] = 1;
        rem++;
      }
    } else {
      string ss = col[i];
      sort(ss.begin(), ss.end());
      if (rem == i + 1) {
        if (ss != col[i]) {
          dc[i] = 1;
          rem++;
          continue;
        } else {
          continue;
        }
      } else {
        if (ss == col[i])
          continue;
        else {
          string col1[n];
          string col2[n];
          for (int j = 0; j < n; j++) {
            for (int k = 0; k <= i; k++) {
              if (!dc.count(k)) {
                col1[j].push_back(s[j][k]);
                col2[j].push_back(s[j][k]);
              }
            }
          }
          sort(col2, col2 + n);
          for (int j = 0; j < n; j++) {
            if (col2[j] != col1[j]) {
              rem++;
              dc[i] = 1;
              break;
            }
          }
        }
      }
    }
  }
  cout << rem;
  return 0;
}
