#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
bool mark[maxn];
char t[maxn][maxn];
int main() {
  int n, m, cnt = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> t[i][j];
    }
  }
  for (int i = 0; i < m; ++i) {
    bool is = true;
    for (int j = 1; j < n; ++j) {
      if (t[j][i] >= t[j - 1][i]) {
        continue;
      }
      bool is2 = false;
      for (int k = 0; k < i; ++k) {
        if (t[j][k] > t[j - 1][k] && !mark[k]) {
          is2 = true;
        }
      }
      if (!is2) {
        is = false;
        mark[i] = true;
      }
    }
    if (is) {
      continue;
    }
    cnt++;
  }
  cout << cnt << endl;
}
