#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000000LL

int main(){
	
	int h,w;
	cin>>h>>w;
	vector<string> s(h);
	rep(i,h)cin>>s[i];
	dsu D(h*w);
	rep(i,h){
		rep(j,w){
			if(j!=w-1 && s[i][j]!='.' && s[i][j]==s[i][j+1])D.merge(i*w+j,i*w+j+1);
			if(i!=h-1 && s[i][j]!='.' && s[i][j]==s[i+1][j])D.merge(i*w+j,(i+1)*w+j);
		}
	}
	rep(i,h){
		rep(j,w){
			if(D.size(i*w+j)>=4)s[i][j] = '.';
		}
	}
	rep(i,h)cout<<s[i]<<endl;
	
	return 0;
}