#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int h,w;
    cin >> h >> w;

    vector<string> s(h);
    vector<vector<int> > m(55, vector<int>(55,0));
    int d[3] = {-1,0,1};

    rep(i,h){
        cin >> s[i];
    }

    int tmp1,tmp2;

    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#'){
                tmp1 = 0;tmp2 = 0;
                rep(k,3){
                    rep(l,3){
                        tmp1 = i + d[k];
                        tmp2 = j + d[l];
                        if(tmp1 != i || tmp2 != j){
                            if(tmp1 >= 0 && tmp1 < h && tmp2 >= 0 && tmp2 < w){
                                m[tmp1][tmp2]++;
                            }
                        }
                    }
                }
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.'){
                cout << m[i][j];
            }
            else{
                cout << s[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}
                /*if(i == 0 && j == 0)
                {
                    //cout << "a" << endl;
                    m[i + 1][j]++;
                    m[i][j + 1]++;
                    m[i + 1][j + 1]++;
                }
                else if (i == h - 1 && j == w - 1)
                {
                    //cout << "d" << endl;
                    if(i != 0){
                        m[i - 1][j]++;
                        m[i][j - 1]++;
                        m[i - 1][j - 1]++;
                    }
                    else{
                        m[i][j-1]++;
                    }
                }
                else if(i == 0 && j == w - 1){
                    m[i+1][j]++;
                    m[i][j-1]++;
                    m[i+1][j-1]++;
                }
                else if(i == h-1 && j == 0){
                    m[i][j+1]++;
                    m[i-1][j]++;
                    m[i-1][j+1]++;
                }
                else if(i == 0)
                {
                    //cout << "b" << endl;//##################################################
                    m[i][j-1]++;
                    m[i][j+1]++;
                    m[i+1][j-1]++;
                    m[i+1][j]++;
                    m[i+1][j+1]++;
                }
                else if(j == 0)
                {
                    //cout << "c" << endl;
                    m[i-1][j]++;
                    m[i+1][j]++;
                    m[i-1][j+1]++;
                    m[i][j+1]++;
                    m[i+1][j+1]++;
                }
                else if(i == h-1)
                {
                    //cout << "e" << endl;
                    m[i][j-1]++;
                    m[i][j+1]++;
                    m[i-1][j-1]++;
                    m[i-1][j]++;
                    m[i-1][j+1]++;
                }
                else if(j == w-1)
                {
                    //cout << "f" << endl;
                    m[i-1][j-1]++;
                    m[i][j-1]++;
                    m[i+1][j-1]++;
                    m[i-1][j]++;
                    m[i+1][j]++;
                }
                else
                {
                    //cout << "g" << endl;
                    m[i-1][j-1]++;
                    m[i-1][j]++;
                    m[i-1][j+1]++;
                    m[i][j-1]++;
                    m[i][j+1]++;
                    m[i+1][j-1]++;
                    m[i+1][j]++;
                    m[i+1][j+1]++;
                }
            }
        }
    }

    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.'){
                cout << m[i][j];
            }
            else{
                cout << s[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}*/

Measured memory_bytes: 256