#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
inline long long FIX(long long a) { return (a % Mod + Mod) % Mod; }
int d[1024];
string Maze[1024];
vector<pair<int, int>> todo[1024];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) cin >> Maze[i];
  todo[0].push_back(make_pair(0, n - 1));
  for (int i = 0; i < m; i++) {
    int f = 0;
    for (auto &X : todo[i]) {
      for (int j = X.first + 1; j <= X.second; j++) {
        if (Maze[j][i] < Maze[j - 1][i]) {
          f = 1;
          break;
        }
      }
    }
    if (f == 1) {
      d[i] = 1;
      todo[i + 1] = todo[i];
    } else {
      for (auto &X : todo[i]) {
        int cur = X.first;
        for (int j = X.first + 1; j <= X.second; j++) {
          if (Maze[j][i] != Maze[j - 1][i]) {
            todo[i + 1].push_back(make_pair(cur, j - 1));
            cur = j;
          }
        }
        todo[i + 1].push_back(make_pair(cur, X.second));
      }
    }
  }
  cout << accumulate(d, d + m, 0) << endl;
  return 0;
}
