#include <bits/stdc++.h>
using namespace std;
char ch[101][101];
bool boo[101];
bool temp[101];
long long int n, m;
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < m; ++i) boo[i] = true;
  for (long long int i = 0; i < n; ++i) temp[i] = false;
  temp[0] = true;
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) cin >> ch[i][j];
  }
  for (long long int j = 0; j < m; ++j) {
    for (long long int i = 1; i < n; ++i) {
      if (ch[i][j] < ch[i - 1][j] && temp[i] == false) {
        boo[j] = false;
        break;
      }
    }
    if (boo[j]) {
      for (long long int i = 1; i < n; ++i) {
        if (ch[i][j] != ch[i - 1][j]) temp[i] = true;
      }
    }
  }
  long long int count = 0;
  for (long long int i = 0; i < m; ++i) {
    if (!boo[i]) count++;
  }
  cout << count << endl;
  return 0;
}
