#include <bits/stdc++.h>
using namespace std;
int z[1005];
string a[1005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int j = 0; j < m; ++j) {
    for (int i = 1; i < n; ++i)
      for (int i1 = 0; i1 < i; ++i1) {
        bool ok = false;
        for (int k = 0; k < j; ++k)
          if (z[k] == 0 && a[i][k] > a[i1][k]) {
            ok = true;
            break;
          }
        if (!ok && a[i][j] < a[i1][j]) z[j] = 1;
      }
  }
  int ans = 0;
  for (int i = 0; i < m; ++i)
    if (z[i]) ++ans;
  cout << ans << '\n';
}
