#include #include using namespace std; using namespace atcoder; using ll=long long; using ull=unsigned long long; using ld=long double; using i128=__int128; using P=pair; template using vc=vector; template using vv=vc>; using vl=vc; using vvl=vc>; using vul=vc; using vs=vc; using vb=vc; #define rep(i,s,n) for(ll i=s;i<(n);i++) #define Rep(i,s,n) for(ll i=n;i>=s;i--) #define nall(x) x.begin(),x.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define pob pop_back #define nexp(v) next_permutation(v) #define prep(v) prev_permutation(v) #define YES cout<<"Yes"<b)a=b;} void chmax(ll &a,ll b){if(a pt; vl rot; auto rotate90(const vs& g){ ll h=g.size(),w=g[0].size(); vs res(w,string(h,'.')); rep(i,0,h)rep(j,0,w)res[j][h-1-i]=g[i][j]; return res; } void solve(){ vs v(m,string(m,'.')); rep(i,0,n){ ll r=rot[i]; auto &now=pt[i][r]; rep(j,0,m){ rep(k,0,m)if(now[j][k]=='#')v[j][k]='#'; } } ll cnt=0; rep(i,0,m)rep(j,0,m)cnt+=(v[i][j]=='#'); chmin(ans,cnt); } void dfs(ll id){ if(id==n){ solve(); return; } rep(i,0,4){ rot[id]=i; dfs(id+1); } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; pt.resize(n,vv(4)); rot.resize(n); rep(i,0,n){ vs s(m); rep(j,0,m)cin >> s[j]; pt[i][0]=s; pt[i][1]=rotate90(pt[i][0]); pt[i][2]=rotate90(pt[i][1]); pt[i][3]=rotate90(pt[i][2]); } dfs(0); cout << ans << endl; }