#include <bits/stdc++.h>
using namespace std;
int m, n;
char mark[1002][1002];
int main() {
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    cin.get();
    cin.get(mark[i], n + 1, '\n');
  }
  int f = 0, t = 0;
  while (!f) {
    f = 1;
    for (int i = 0; i < m - 1; i++) {
      f = 1;
      for (int j = 0; j <= n; j++)
        if (mark[i][j] > mark[i + 1][j]) {
          for (int k = 0; k < m; k++) strcpy(mark[k] + j, mark[k] + j + 1);
          t++;
          f = 0;
          break;
        } else if (mark[i][j] < mark[i + 1][j])
          break;
      if (f == 0) break;
    }
  }
  cout << t;
  return 0;
}
