import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;
import std.format;

void main()
{
  auto a = readln.chomp.split.map!(to!int);
  auto h = a[0];
  auto w = a[1];
  char[][] map = new char[][](h + 2, w + 2);
  foreach (ref arr; map) {
    arr[] = '.';
  }
  foreach (i; 0..h) {
    auto s = readln;
    foreach (j; 0..w) {
      map[i + 1][j + 1] = s[j];
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (map[i][j] == '#') {
        write = '#';
        continue;
      }
      int cnt = 0;
      for (int dx = -1; dx <= 1; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
          cnt += map[i + dy][j + dx] == '#';
        }
      }
      cnt.write;
    }
    writeln;
  }
}
