process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var dx = [-1, 0, 1, -1, 1, -1, 0, 1];
    var dy = [-1, -1, -1, 0, 0, 1, 1, 1];

    var size = input[0].split(' ');
    var h = parseInt(size[0], 10);
    var w = parseInt(size[1], 10);
    var s = new Array(h);
    for (var i = 0; i < h; i++) {
        s[i] = new Array(w);
        var grids = input[i + 1].split('');
        for (var j = 0; j < w; j++) {
            if (grids[j] == '.') {
                s[i][j] = 0;
            }
            else {
                s[i][j] = -1;
            }
        }
    }

    for (var i = 0; i < h; i++) {
        for (var j = 0; j < w; j++) {
            if (s[i][j] < 0) {
                continue;
            }
            for (var k = 0; k < 8; k++) {
                if (i + dy[k] < 0 || i + dy[k] >= h || j + dx[k] < 0 || j + dx[k] >= w) {
                    continue;
                }
                if (s[i + dy[k]][j + dx[k]] < 0) {
                    s[i][j]++;
                }
            }
        }
    }

    for (var i = 0; i < h; i++) {
        var line = '';
        for (var j = 0; j < w; j++) {
            if (s[i][j] < 0) {
                line += '#';
            }
            else {
                line += '' + s[i][j];
            }
        }
        console.log(line);
    }

    return 0;
}
