#include <bits/stdc++.h>
int main() {
  int h, w;
  char s[50][50] = {0};
  std::cin >> h >> w;
  for (int i = 0; i < h; i++) std::cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        int count = 0;
        if (i == 0) {
          if (j == 0) {
            if (s[i][j + 1] == '#') count++;
            if (s[i + 1][j + 1] == '#') count++;
            if (s[i + 1][j] == '#') count++;
          } else if (j == w - 1) {
            if (s[i][j - 1] == '#') count++;
            if (s[i + 1][j - 1] == '#') count++;
            if (s[i + 1][j] == '#') count++;
          } else {
            if (s[i][j + 1] == '#') count++;
            if (s[i + 1][j + 1] == '#') count++;
            if (s[i][j - 1] == '#') count++;
            if (s[i + 1][j - 1] == '#') count++;
            if (s[i + 1][j] == '#') count++;
          }
        } else if (i == h - 1) {
          if (j == 0) {
            if (s[i][j + 1] == '#') count++;
            if (s[i - 1][j + 1] == '#') count++;
            if (s[i - 1][j] == '#') count++;
          } else if (j == w - 1) {
            if (s[i][j - 1] == '#') count++;
            if (s[i - 1][j - 1] == '#') count++;
            if (s[i - 1][j] == '#') count++;
          } else {
            if (s[i][j + 1] == '#') count++;
            if (s[i - 1][j + 1] == '#') count++;
            if (s[i][j - 1] == '#') count++;
            if (s[i - 1][j - 1] == '#') count++;
            if (s[i - 1][j] == '#') count++;
          }
        } else {
          if (j == 0) {
            if (s[i - 1][j - 1] == '#') count++;
            if (s[i - 1][j] == '#') count++;
            if (s[i][j - 1] == '#') count++;
            if (s[i + 1][j - 1] == '#') count++;
            if (s[i + 1][j] == '#') count++;
          } else if (j == w - 1) {
            if (s[i - 1][j + 1] == '#') count++;
            if (s[i - 1][j] == '#') count++;
            if (s[i][j + 1] == '#') count++;
            if (s[i + 1][j + 1] == '#') count++;
            if (s[i + 1][j] == '#') count++;
          } else {
            if (s[i - 1][j - 1] == '#') count++;
            if (s[i][j - 1] == '#') count++;
            if (s[i + 1][j - 1] == '#') count++;
            if (s[i - 1][j + 1] == '#') count++;
            if (s[i - 1][j] == '#') count++;
            if (s[i][j + 1] == '#') count++;
            if (s[i + 1][j + 1] == '#') count++;
            if (s[i + 1][j] == '#') count++;
          }
        }
        s[i][j] = '0' + count;
      }
    }
  }
  for (int i = 0; i < h; i++) std::cout << s[i] << std::endl;
}
