function Main(s) {
  var s = s.split("\n");
  var hw = s[0].split(" ").map(e => e*1);
  var head = ["_".repeat(hw[1] + 2)];
  var tail = ["_".repeat(hw[1] + 2)];
  for (var i = 1; i <= hw[0]; i++) {
    s[i] = "_" + s[i] + "_";
  }
  var x = head.concat(s.slice(1, hw[0] + 1));
  var y = x.concat(tail);
  var ans = new Array(hw[0]).fill("");
  var cnt;
  for (var i = 1; i < hw[0] + 1; i++) {
    for (var j = 1; j < hw[1] + 1; j++) {
      cnt = 0;
      if (y[i][j] === ".") {
        if (y[i - 1][j - 1] === "#") cnt++;
        if (y[i][j - 1] === "#") cnt++;
        if (y[i + 1][j - 1] === "#") cnt++;
        if (y[i - 1][j] === "#") cnt++;
        if (y[i + 1][j] === "#") cnt++;
        if (y[i - 1][j + 1] === "#") cnt++;
        if (y[i][j + 1] === "#") cnt++;
        if (y[i + 1][j + 1] === "#") cnt++;
        ans[i - 1] += String(cnt);
      } else {
        ans[i - 1] += "#";
      }
    }
  }
  for (var i of ans) console.log(i);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));