#include <iostream>  
    #include <map>  
    #include <set>  
    #include <string>  
    #include<string.h>  
    #include <cstring>  
    #include <cstdio>  
    #include <algorithm>  
    #include <cmath>  
    #include <queue>  
    #include <vector>  
    using namespace std;  
    typedef long long ll;  
    const int maxn=55;  
    char mp[maxn][maxn];  
    int f[maxn][maxn];  
    int main(){  
        int h,w;  
        scanf("%d%d",&h,&w);  
        memset(f,0,sizeof(f));  
        for(int i=0;i<h;i++){  
            scanf("%s",mp[i]);  
        }  
        for(int i=0;i<h;i++){  
            for(int j=0;j<w;j++){  
                if(mp[i][j]=='#'){  
                    if(i-1>=0){  
                        f[i-1][j]++;  
                    }  
                    if(j-1>=0){  
                        f[i][j-1]++;  
                    }  
                    if(i+1<h){  
                        f[i+1][j]++;  
                    }  
                    if(j+1<w){  
                        f[i][j+1]++;  
                    }  
                    if(i-1>=0&&j-1>=0){  
                        f[i-1][j-1]++;  
                    }  
                    if(i+1<h&&j-1>=0){  
                        f[i+1][j-1]++;  
                    }  
                    if(i-1>=0&&j+1<w){  
                        f[i-1][j+1]++;  
                    }  
                    if(i+1<h&&j+1<w){  
                        f[i+1][j+1]++;  
                    }  
                }  
            }  
        }  
        for(int i=0;i<h;i++){  
            for(int j=0;j<w;j++){  
                if(mp[i][j]=='#') printf("#");  
                else printf("%d",f[i][j]);  
            }printf("\n");  
        }  
        return 0;  
    }  