#include <bits/stdc++.h>
using namespace std;
int count_surround_bomb(int H, int W, int h, int w, vector<string> v) {
  int count = 0;
  if (h > 0 && w > 0 && v[h - 1][w - 1] == '#') count++;
  if (h > 0 && v[h - 1][w] == '#') count++;
  if (h > 0 && w > W - 1 && v[h - 1][w + 1] == '#') count++;
  if (w > 0 && v[h][w - 1] == '#') count++;
  if (w > W - 1 && v[h][w + 1] == '#') count++;
  if (h > H - 1 && w > 0 && v[h + 1][w - 1] == '#') count++;
  if (h > H - 1 && v[h + 1][w] == '#') count++;
  if (h > H - 1 && w > W - 1 && v[h + 1][w + 1] == '#') count++;
  return count;
}
int main() {
  int h, w;
  vector<string> v;
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) {
    char line[w + 1];
    scanf("%s", line);
    v.push_back(line);
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] == '#') {
        continue;
      } else {
        int n = count_surround_bomb(h, w, i, j, v);
        v[i][j] = '0' + n;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    printf("%s\n", v[i].c_str());
  }
  return 0;
}
