#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T>
inline T abs(T x) {
  return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 1000;
struct Input {
  int n, m;
  string s[N];
  bool read() {
    if (!(cin >> n >> m)) {
      return 0;
    }
    getline(cin, s[0]);
    for (int i = 0; i < int(n); ++i) {
      getline(cin, s[i]);
    }
    return 1;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  int ans;
  void write() { cout << ans << endl; }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
struct Solution : Data {
  bool done[N];
  void solve() {
    memset(done, 0, sizeof done);
    ans = 0;
    for (int i = 0; i < int(m); ++i) {
      bool ok = 1;
      for (int j = 0; j < int(n - 1); ++j) {
        if (!done[j] && s[j][i] > s[j + 1][i]) {
          ok = 0;
        }
      }
      if (!ok) {
        ans++;
        continue;
      }
      for (int j = 0; j < int(n - 1); ++j) {
        if (s[j][i] < s[j + 1][i]) {
          done[j] = 1;
        }
      }
    }
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
