#include using namespace std; using ll = long long; using ull = unsigned long long; constexpr int MOD = 998244353; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, l, r) for (int i = (l); i < (int)(r); i++) #define all(v) v.begin(), v.end() int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin>>H>>W; vectorS(H); for(auto &i:S)cin>>i; vector rt(H,vector(W,-1)); auto xy2i=[W](int x,int y){ return x*W+y; }; auto i2xy=[W](int i){ return make_pair(i/W,i%W); }; auto bound_ok=[H,W](int x,int y){ return x>=0&&x=0&&yer; rep(i,H){ rep(j,W){ if(rt[i][j]!=-1)continue; queuebfs; rt[i][j]=xy2i(i,j); bfs.push(xy2i(i,j)); int cnt=0; while(bfs.size()){ auto [x,y]=i2xy(bfs.front()); bfs.pop(); cnt++; rep(k,4){ int x2=x+dx[k],y2=y+dy[k]; if(bound_ok(x2,y2)&&S[x2][y2]==S[x][y]&&rt[x2][y2]==-1){ rt[x2][y2]=xy2i(i,j); bfs.push(xy2i(x2,y2)); } } } if(cnt>=4)er.insert(xy2i(i,j)); } } rep(i,H){ rep(j,W){ if(er.contains(rt[i][j]))cout<<'.'; else cout<