#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 100 + 10;
int n, m, res;
string s[N];
bool flag[N][N], mark[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int c = 0; c < m; c++) {
    for (int i = 0; i < n && !mark[c]; i++)
      for (int j = i + 1; j < n; j++) {
        if (flag[i][j]) continue;
        if (s[i][c] < s[j][c]) break;
        if (s[i][c] == s[j][c]) continue;
        mark[c] = true;
        break;
      }
    if (mark[c]) {
      res++;
      continue;
    }
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        if (s[i][c] < s[j][c]) flag[i][j] = true;
  }
  cout << res << endl;
  return 0;
}
