#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int h, w; cin >> h >> w; vector g(h); for (int i = 0; i < h; i++) { cin >> g[i]; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; auto is_in = [&](int x, int y) { return 0 <= x && x < h && 0 <= y && y < w; }; vector> vis(h, vector(w)); vector ans = g; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (vis[i][j]) { continue; } deque> dq{{i, j}}; vector> v{{i, j}}; vis[i][j] = true; while (!dq.empty()) { auto [x, y] = dq.front(); dq.pop_front(); for (int k = 0; k < 4; k++) { int nx = x + dx[k]; int ny = y + dy[k]; if (is_in(nx, ny) && !vis[nx][ny] && g[nx][ny] == g[x][y]) { vis[nx][ny] = true; dq.push_back({nx, ny}); v.push_back({nx, ny}); } } } if (v.size() >= 4) { for (auto [x, y] : v) { ans[x][y] = '.'; } } } } for (int i = 0; i < h; i++) { cout << ans[i] << "\n"; } }