#include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) static const double pi = 3.141592653589793; const ll INF = 1LL << 60; const ll mod = 1000000007; const ll imod = 998244353; using mint = modint998244353; vector dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; ll P(ll x, ll n) { ll ret = 1; while (n > 0) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } void seek(bool f){ cout << (f ? "Yes" : "No") << endl; } int main(){ int H, W; cin >> H >> W; char A[H][W]; rep(i, H){ rep(j, W){ cin >> A[i][j]; } } dsu uf(H * W); rep(i, H){ rep(j, W){ rep(d, 4){ int ni = i + dx[d], nj = j + dy[d]; if(ni < 0 or ni >= H or nj < 0 or nj >= W){ continue; } if(A[i][j] == A[ni][nj]){ uf.merge(i * W + j, ni * W + nj); } } } } for(auto g : uf.groups()){ if(g.size() >= 4){ for(int c : g){ int h = c / W, w = c % W; A[h][w] = '.'; } } } rep(i, H){ rep(j, W){ cout << A[i][j]; } cout << "\n"; } }