#include <iostream>

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

int main(){
    cin.tie(0);
    int c;
    int H,W;
    cin >> H >> W;
    char S[51][51];
    char C[51][51];
    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