#include using namespace std; vector rotatem90(vector a){ int h = a.size(), w = a[0].size(); vector ret(h, string(w, '?')); for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ ret[x][h - 1 - y] = a[y][x]; } } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector> a(n); for(int i = 0; i < n; i++){ vector A(m); for(auto &&s : A) cin >> s; for(int j = 0; j < 4; j++){ __int128 S = 0; for(int y = 0; y < m; y++){ for(int x = 0; x < m; x++){ if(A[y][x] == '#') a[i][j] |= __int128(1) << (y * m + x); } } A = rotatem90(A); } } int ans = m * m; for(int S = 0; S < (1 << (2 * n)); S++){ __int128 U = 0; for(int j = 0; j < n; j++){ U |= a[j][(S >> (2 * j)) & 3]; } ans = min(ans, (int)(__builtin_popcountll(U & 0xFFFF'FFFF'FFFF'FFFFULL) + __builtin_popcountll((U >> 64) & 0xFFFF'FFFF'FFFF'FFFFULL))); } cout << ans << '\n'; }