#include <bits/stdc++.h>
#define double long double
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int h,w,cnt=0;char a[55][55];
signed main() {
	cin>>h>>w;
	rep(i,h){rep(j,w)cin>>a[i][j];}
	rep(i,h){
		rep(j,w){
			if(a[i][j]=='.'){
				for(int k=-1;k<2;k++){
					for(int l=-1;l<2;l++){
						if(a[i+k][j+l]=='#'&&i+k>=0&&i+k<h&&j+l>=0&&j+l<w)cnt++;
					}
				}
				a[i][j]=cnt+'0';
			}
			cout<<a[i][j];
			cnt=0;
		}
		cout<<endl;
	}
	cout<<endl;
}
