#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point() {}
  point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T power(T n, T p) {
  T res = 1;
  for (int i = 0; i < p; i++) res *= n;
  return res;
}
template <class T>
double getdist(T a, T b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
  stringstream ss(s);
  ss >> ret;
  return ret;
}
template <class T>
string tostring(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
void show(T a) {
  cout << a << endl;
}
template <class T>
void show(T a, T b) {
  cout << a << ' ' << b << endl;
}
string arr[1010];
string last[1010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, i, res = 0, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> arr[i];
  for (j = 0; j < m; j++) {
    int diff = 0, mxpos = 0;
    vector<string> cur, sorted;
    set<string> ss;
    for (i = 0; i < n; i++) {
      cur.push_back(last[i] + arr[i][j]);
      sorted.push_back(last[i] + arr[i][j]);
      ss.insert(last[i] + arr[i][j]);
    }
    sort(sorted.begin(), sorted.end());
    if (cur != sorted) {
      res++;
      continue;
    }
    if (cur == sorted && (int)(ss.size()) == n) break;
    for (i = 0; i < n; i++) last[i] += arr[i][j];
  }
  cout << res << endl;
  return 0;
}
