#include #include #define For(i, a, b) for(long long i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(long long i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; vector di = {-1, 0, 1, 0}; vector dj = {0, 1, 0, -1}; int main() { int h, w; cin >> h >> w; vector> s(h, vector(w)); rep(i, h) { rep(j, w) { cin >> s[i][j]; } } auto inc = [&](int i, int j) { return (0 <= i && i < h && 0 <= j && j < w); }; atcoder::dsu uf(h * w); rep(i, h) { rep(j, w) { rep(k, 4) { int ni = i + di[k], nj = j + dj[k]; if (!inc(ni, nj)) { continue; } if (s[i][j] == s[ni][nj]) { uf.merge(w * i + j, w * ni + nj); } } } } auto g = uf.groups(); vector> ans = s; for (auto v : g) { if ((int)v.size() < 4) { continue; } for (int x : v) { int i = x / w, j = x % w; ans[i][j] = '.'; } } rep(i, h) { rep(j, w) { cout << ans[i][j]; } cout << endl; } }