#include<bits/stdc++.h>
 
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

string mas[100];
char masa[100][100];
signed main(){
	int h,w;
	cin >> h >> w;
	rep(i,h) cin >> mas[i];
	int cnt = 0;
	rep(i,h){
		rep(j,w){
			if(mas[i][j] == '#') cout << '#';
			else if(i == 0){
				if(j == 0){
					if(mas[i][j+1] == '#') ++cnt;
					if(mas[i+1][j] == '#') ++cnt;
					if(mas[i+1][j+1] == '#') ++cnt;
					cout << cnt;
					cnt = 0;
				}
				else if(j == w-1){
					if(mas[i][j-1] == '#') ++cnt;
					if(mas[i+1][j] == '#') ++cnt;
					if(mas[i+1][j-1] == '#') ++cnt;
					cout << cnt;
					cnt = 0;
				}
				else{
					if(mas[i][j+1] == '#') ++cnt;
					if(mas[i][j-1] == '#') ++cnt;
					if(mas[i+1][j-1] == '#') ++cnt;
					if(mas[i+1][j] == '#') ++cnt;
					if(mas[i+1][j+1] == '#') ++cnt;
					cout << cnt;
					cnt = 0;
				}
			}
			else if(i == h - 1){
                if(j == 0){
                    if(mas[i][j+1] == '#') ++cnt;
                    if(mas[i-1][j] == '#') ++cnt;
                    if(mas[i-1][j+1] == '#') ++cnt;
                    cout << cnt;
                    cnt = 0;
                }
                else if(j == w-1){
                    if(mas[i][j-1] == '#') ++cnt;
                    if(mas[i-1][j] == '#') ++cnt;
                    if(mas[i-1][j-1] == '#') ++cnt;
                    cout << cnt;
                    cnt = 0;
                }
                else{
                    if(mas[i][j+1] == '#') ++cnt;
                    if(mas[i][j-1] == '#') ++cnt;
                    if(mas[i-1][j-1] == '#') ++cnt;
                    if(mas[i-1][j] == '#') ++cnt;
                    if(mas[i-1][j+1] == '#') ++cnt;
                    cout << cnt;
                    cnt = 0;
                }
            }
			else {
                if(j == 0){
                    if(mas[i][j+1] == '#') ++cnt;
                    if(mas[i-1][j] == '#') ++cnt;
                    if(mas[i-1][j+1] == '#') ++cnt;
					if(mas[i+1][j] == '#') ++cnt;
					if(mas[i+1][j+1] == '#') ++cnt;
                    cout << cnt;
                    cnt = 0;
                }
                else if(j == w-1){
                    if(mas[i][j-1] == '#') ++cnt;
                    if(mas[i-1][j] == '#') ++cnt;
                    if(mas[i-1][j-1] == '#') ++cnt;
					if(mas[i+1][j] == '#') ++cnt;
					if(mas[i+1][j-1] == '#') ++cnt;
                    cout << cnt; 
                    cnt = 0;
                }
                else{
                    if(mas[i][j+1] == '#') ++cnt;
                    if(mas[i][j-1] == '#') ++cnt;
                    if(mas[i-1][j-1] == '#') ++cnt;
                    if(mas[i-1][j] == '#') ++cnt;
                    if(mas[i-1][j+1] == '#') ++cnt;
					if(mas[i+1][j-1] == '#') ++cnt;
					if(mas[i+1][j] == '#') ++cnt;
					if(mas[i+1][j+1] == '#') ++cnt;
                    cout << cnt;
                    cnt = 0;
                }
            }
			if(j == w-1) cout << '\n';
		}
	}
    return 0;	
}


Measured memory_bytes: 256