#include <bits/stdc++.h>
using namespace std;
struct point {
  int x;
  int y;
};
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) cin >> s[i];
  struct point adj[8] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
                         {0, 1},   {1, -1}, {1, 0},  {1, 1}};
  int t[h][w];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) t[i][j] = 0;
  int ax, ay;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        t[i][j] = 9;
        continue;
      }
      for (int k = 0; k < 8; k++) {
        ax = i + adj[k].x;
        ay = j + adj[k].y;
        if (0 <= ax && ax < h && 0 <= ay && ay < w && s[ax][ay] == '#')
          t[i][j]++;
      }
    }
  }
  char ch[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '#'};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ch[t[i][j]];
    }
    cout << endl;
  }
  return 0;
}
