import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int h, w;
  readf("%s %s\n", &h, &w);
  auto m = new char[][](h, w);
  auto cnt = new int[][](h, w);
  foreach (i; 0..h) {
    m[i] = readln.chomp.to!(char[]);
    foreach (j; 0..w) {
      if (m[i][j] == '#') {
        cnt[i][j] = -1;
        foreach (x; i-1..i+2) {
          foreach (y; j-1..j+2) {
            if (x < 0 || x >= h) continue;
            if (y < 0 || y >= w) continue;
            if (cnt[x][y] == -1) continue;
            cnt[x][y]++;
          }
        }
      }
    }
  }

  foreach (i; 0..h) {
    foreach (j; 0..w) {
      if (cnt[i][j] == -1) write("#");
      else write(cnt[i][j]);
    }
    writeln("");
  }
}
