"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const H = ~~arg[0].split(" ")[0];
    const W = ~~arg[0].split(" ")[1];
    
    const table = arg.slice(1, H + 1).map(n=>n.split(""));
    
    const dx = [0, 1, 1, 1, 0, -1, -1, -1];
    const dy = [-1, -1, 0, 1, 1, 1, 0, -1];
    
    for(let i=0; i<H; i++) {
        for(let j=0; j<W; j++) {
            let cnt = 0;
            for(let k=0; k<8; k++) {
                const nx = dx[k] + j;
                const ny = dy[k] + i;
                
                if(ny < 0 || nx < 0) {
                    continue;
                }
                
                if(ny > H - 1 || nx > W - 1) {
                    continue;
                }
                
                
                if(table[ny][nx] === "#") {
                    cnt++;
                }
            }
            
            if(table[i][j] === ".") {
                table[i][j] = cnt;
            }
        }
    }
    
    console.log(table.map(n=>n.join("")).join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));