#include <bits/stdc++.h>
using namespace std;
vector<char> V[100];
vector<int> check(vector<int> &cur, vector<char> &st) {
  int n = cur.size();
  vector<int> res = {0};
  for (int i = 1; i < n; ++i) {
    for (int j = cur[i - 1] + 1; j < cur[i]; ++j)
      if (st[j] < st[j - 1])
        return {};
      else if (st[j] > st[j - 1])
        res.push_back(j);
    res.push_back(cur[i]);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  char ch;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) V[j].push_back((cin >> ch, ch));
  vector<int> cur = {0, n};
  int ans = m;
  for (int i = 0; i < m; ++i) {
    auto re = check(cur, V[i]);
    if (!re.empty()) {
      cur = re;
      --ans;
    }
  }
  cout << ans << endl;
  return 0;
}
