//bài này có sử dụng kiến thức về trie, em có thể đọc thêm tại đây nhé: bom.so/J2Zln5
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxn = 25 * (int)1e6, inf = 1e18,mxc = 5005;
map<int,int> mp[26],depth,dem;
int cnt,ans,n,m;
char c[mxc][mxc];
string srr[mxc];
int ins(string &s)
{
int u = 0;
for(auto c : s)
{
int id = c - 'a';
if(!mp[id][u])
{
mp[id][u] = ++cnt;
}
depth[mp[id][u]] = depth[u] + 1;
u = mp[id][u];
dem[u]++;
if(dem[u] > 1) ans = max(ans, depth[u]);
//cout << ans << '\n';
}
return u;
}
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> c[i][j];
for(int j = 0; j < m ; j++)
{
for(int i = n - 1; i >= 0; i--) srr[j] += c[i][j];
ins(srr[j]);
}
cout << n - ans - 1 << '\n';
return 0;
}
Ly9iw6BpIG7DoHkgY8OzIHPhu60gZOG7pW5nIGtp4bq/biB0aOG7qWMgduG7gSB0cmllLCBlbSBjw7MgdGjhu4MgxJHhu41jIHRow6ptIHThuqFpIMSRw6J5IG5ow6k6IGJvbS5zby9KMlpsbjUKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCmNvbnN0IGludCBteG4gPSAyNSAqIChpbnQpMWU2LCBpbmYgPSAxZTE4LG14YyA9IDUwMDU7Cm1hcDxpbnQsaW50PiBtcFsyNl0sZGVwdGgsZGVtOwppbnQgY250LGFucyxuLG07CmNoYXIgY1tteGNdW214Y107CnN0cmluZyBzcnJbbXhjXTsKaW50IGlucyhzdHJpbmcgJnMpCnsKICAgIGludCB1ID0gMDsKICAgIGZvcihhdXRvIGMgOiBzKQogICAgewogICAgICAgIGludCBpZCA9IGMgLSAnYSc7CiAgICAgICAgaWYoIW1wW2lkXVt1XSkKICAgICAgICB7CiAgICAgICAgICAgIG1wW2lkXVt1XSA9ICsrY250OwogICAgICAgIH0KICAgICAgICBkZXB0aFttcFtpZF1bdV1dID0gZGVwdGhbdV0gKyAxOwogICAgICAgIHUgPSBtcFtpZF1bdV07CiAgICAgICAgZGVtW3VdKys7CiAgICAgICAgaWYoZGVtW3VdID4gMSkgYW5zID0gbWF4KGFucywgZGVwdGhbdV0pOwogICAgICAgIC8vY291dCA8PCBhbnMgPDwgJ1xuJzsKICAgIH0KICAgIHJldHVybiB1Owp9CmludDMyX3QgbWFpbigpCnsKICAgIGNpbi50aWUoMCktPnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbiA+PiBuID4+IG07CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBmb3IoaW50IGogPSAwOyBqIDwgbTsgaisrKSBjaW4gPj4gY1tpXVtqXTsKICAgIGZvcihpbnQgaiA9IDA7IGogPCBtIDsgaisrKQogICAgewogICAgICAgIGZvcihpbnQgaSA9IG4gLSAxOyBpID49IDA7IGktLSkgc3JyW2pdICs9IGNbaV1bal07CiAgICAgICAgaW5zKHNycltqXSk7CiAgICB9CiAgICBjb3V0IDw8IG4gLSBhbnMgLSAxIDw8ICdcbic7CiAgICByZXR1cm4gMDsKfQo=