#include <bits/stdc++.h>
const long double pi = acos(-1);
using namespace std;
char a[105][105], row[105], col[105];
bool vis[105];
int main() {
  int n, m;
  cin >> n >> m;
  bool b = false;
  if (n == 1) {
    cout << "0\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int res = 0, sum = 0;
  vector<char> ans;
  for (int k = 0; k < m; k++) {
    vector<string> ve;
    for (int i = 0; i < n; i++) {
      string s = "";
      for (int j = k; j >= 0; j--) {
        if (!vis[j]) s += a[i][j];
      }
      reverse(s.begin(), s.end());
      ve.push_back(s);
    }
    vector<string> vec;
    for (string s : ve) vec.push_back(s);
    sort(vec.begin(), vec.end());
    if (ve == vec) {
      ans.push_back(a[0][k]);
      res++;
      sum++;
      continue;
    }
    vis[k] = true;
    sum = 0;
  }
  cout << m - res << "\n";
  return 0;
}
