#include <iostream>

using namespace std;
#define LOOP(val,times) for(val=0;val<times;val++)

int main(){
    cin.tie(0);
    int i,j,k,l,c;
    int H,W;
    cin >> H >> W;
    char S[H][W+1];
    char C[H][W+1];
    LOOP(i,H){
        cin >> S[i];
    }
    LOOP(i,H){
        LOOP(j,W){
            c = 0;
            if(S[i][j]=='#'){//#の時例外
                C[i][j] = '#' ;
                continue;
            }else{
                if(i==0){//1段目
                    if(j==0){
                        LOOP(k,2){
                            LOOP(l,2){
                                if (S[i+k][j+l] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }else if(j==W-1){
                        LOOP(k,2){
                            LOOP(l,2){
                                if (S[i+k][j+l-1] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }else{
                        LOOP(k,2){
                            LOOP(l,3){
                                if (S[i+k][j+l-1] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }
                }else if(i==H-1){//最終段
                    if(j==0){
                        LOOP(k,2){
                            LOOP(l,2){
                                if (S[i+k-1][j+l] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }else if(j==W-1){
                        LOOP(k,2){
                            LOOP(l,2){
                                if (S[i+k-1][j+l-1] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }else{
                        LOOP(k,2){
                            LOOP(l,3){
                                if (S[i+k-1][j+l-1] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }
                }else{
                    if(j==0){
                        LOOP(k,3){
                            LOOP(l,2){
                                if (S[i+k-1][j+l] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }else if(j==W-1){
                        LOOP(k,3){
                            LOOP(l,2){
                                if (S[i+k-1][j+l-1] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }else{
                        LOOP(k,3){
                            LOOP(l,3){
                                if (S[i+k-1][j+l-1] =='#')
                                c++;
                            }
                        }
                        C[i][j] = '0'+ c;
                    }
                }
            }
        }
    }
    LOOP(i,H){
        LOOP(j,W){
            cout << C[i][j];
        }
        cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 256