#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    int H, W;
    cin >> H >> W;
    char bomb[H + 2][W + 2] = {'.'};
    rep(i, H) rep(j, W) cin >> bomb[i + 1][j + 1];
    for (int i = 1; i < (H + 1); i++)
    {
        for (int j = 1; j < (W + 1); j++)
        {
            if (bomb[i][j] == '.')
            {
                int counter = 0;
                if (bomb[i - 1][j - 1] == '#')
                    counter++;
                if (bomb[i - 1][j] == '#')
                    counter++;
                if (bomb[i - 1][j + 1] == '#')
                    counter++;
                if (bomb[i][j - 1] == '#')
                    counter++;
                if (bomb[i][j + 1] == '#')
                    counter++;
                if (bomb[i + 1][j - 1] == '#')
                    counter++;
                if (bomb[i + 1][j] == '#')
                    counter++;
                if (bomb[i + 1][j + 1] == '#')
                    counter++;
                bomb[i][j] = counter + '0';
            }
            cout << bomb[i][j];
        }
        cout << endl;
    }
}