#include using namespace std; using ll = long long; #define rep(i,m,n) for(int i=m; i bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } template bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } const int dy[4] = {1, 0, -1, 0}; const int dx[4] = {0, 1, 0, -1}; struct UnionFind{ vector siz, parent; UnionFind(){} UnionFind(int n){ siz.resize(n, 0); parent.resize(n, 0); for(int i=0; i siz[y]){ parent[y] = x; siz[x] += siz[y]; }else{ parent[x] = y; siz[y] += siz[x]; } return true; } int find_root(int x){ if(x != parent[x]) parent[x] = find_root(parent[x]); return parent[x]; } int tree_size(int x){ return siz[find_root(x)]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int H, W; cin >> H >> W; vector G(H); rep(y, 0, H) cin >> G[y]; UnionFind UF(H*W); rep(y, 0, H) rep(x, 0, W) rep(d, 0, 4){ int ny = y + dy[d], nx = x + dx[d]; if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue; if(G[y][x] == G[ny][nx]) UF.unite(y*W + x, ny*W + nx); } rep(y, 0, H){ rep(x, 0, W){ if(UF.tree_size(y*W + x) >= 4) cout << '.'; else cout << G[y][x]; } cout << endl; } return 0; }