#include <iostream>
#include <string>
#include <vector>

using namespace std;

using Grid = vector<string>;

constexpr char kBomb = '#';
constexpr char kEmpty = '.';

bool InBounds(const Grid &g, int x, int y)
{
    return 0 <= x && x < (int)g.size() && 0 <= y && y < (int)g[0].size();
}

int CountBombs(const Grid &g, int x, int y)
{
    static const vector<pair<int, int>> kMods = {
        {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}
    };

    int bombs = 0;
    for (const auto &mod : kMods) {
        int mx = x + mod.first;
        int my = y + mod.second;
        if (InBounds(g, mx, my) && g[mx][my] == kBomb) {
            bombs += 1;
        }
    }
    return bombs;
}

int main()
{
    int rows, cols;
    cin >> rows >> cols;
    cin.get();

    Grid grid(rows);
    for (auto &row : grid) {
        getline(cin, row);
    }

    for (int i = 0; i < rows; i += 1) {
        for (int j = 0; j < cols; j += 1) {
            if (grid[i][j] == kEmpty) {
                grid[i][j] = CountBombs(grid, i, j) + '0';
            }
        }
    }

    for (const auto &row : grid) {
        cout << row << "\n";
    }

    return 0;
}
