#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <class T>
bool umin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool umax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  if (n == 1) {
    cout << 0;
    return;
  }
  vector<bool> st(m);
  int ans = 0;
  for (int j = 0; j < m; ++j) {
    bool ok = 1;
    vector<bool> cp = st;
    for (int i = 1; i < n; ++i) {
      if (s[i][j] < s[i - 1][j] && st[i] == false) {
        ans++;
        ;
        ok = 0;
        break;
      }
      if (s[i][j] > s[i - 1][j]) {
        cp[i] = 1;
      }
    };
    if (ok) {
      for (int k = 0; k < n; ++k) st[k] = st[k] || cp[k];
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
