#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, m;
string s[2000];
int u[2000];
int main() {
  ios::sync_with_stdio(0);
  while (cin >> n >> m) {
    for (int i = 0; i < n; ++i) cin >> s[i];
    int k = 0;
    for (int j = 0; j < m; ++j) {
      bool d = false;
      for (int i = 1; i < n; ++i)
        if (s[i][j] < s[i - 1][j] && !u[i - 1]) {
          k++;
          d = true;
          break;
        }
      if (!d)
        for (int i = 1; i < n; ++i)
          if (s[i][j] > s[i - 1][j]) u[i - 1] = 1;
    }
    cout << k << endl;
  }
  return 0;
}
