#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10, big = 1e18, mod = 1e9 + 7;
long long n, m, ans;
char a[110][110];
bool vis[110];
vector<int> v;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < m; i++) {
    bool check = true;
    for (int j = 1; j < n; j++) {
      if (a[j][i] > a[j - 1][i]) v.push_back(j);
      if (a[j][i] < a[j - 1][i] && (!vis[j])) check = false;
    }
    if (!check)
      ans++;
    else
      for (auto x : v) vis[x] = true;
    v.clear();
  }
  cout << ans;
  return 0;
}
