#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const double EPS = 1e-8;
int n, m;
int mat[100][100];
bool okay[100];
bool clash(int col) {
  for (int row = 1; row < n; row++) {
    if (mat[row][col] < mat[row - 1][col] && !okay[row]) return true;
  }
  for (int i = 1; i < n; i++) {
    if (mat[i][col] > mat[i - 1][col]) okay[i] = true;
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char dummy;
      cin >> dummy;
      mat[i][j] = (int)dummy;
    }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (clash(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}
