#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[1000010][1000010];
char c_[1000010][1000010];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) cin>>c[i][j];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(c[i][j]=='.'){
				if(c[i-1][j-1]=='#'||c[i-1][j]=='#'||c[i-1][j+1]=='#'||c[i][j-1]=='#'||c[i][j+1]=='#'||c[i+1][j-1]=='#'||c[i+1][j]=='#'||c[i+1][j+1]=='#'){
					c_[i][j]='#';
				}else c_[i][j]='.';
			}else c_[i][j]='.';
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(c_[i][j]=='.'){
				if(c_[i-1][j-1]=='#'||c_[i-1][j]=='#'||c_[i-1][j+1]=='#'||c_[i][j-1]=='#'||c_[i][j+1]=='#'||c_[i+1][j-1]=='#'||c_[i+1][j]=='#'||c_[i+1][j+1]=='#'){
					cout<<'#';
				}else cout<<'.';
			}else cout<<'.';
		}
		cout<<endl;
	}
	return 0;
}