#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, m;
int lq[maxn][maxn], fx[8][2] = {{1, 0},  {0, 1},   {1, 1},  {-1, 0},
                                {0, -1}, {-1, -1}, {1, -1}, {-1, 1}};
char s[maxn];
struct node {
  int x, y;
};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    for (int j = 0; j <= m; ++j)
      if (s[j] == '#')
        lq[i][j + 1] = -1;
      else
        lq[i][j + 1] = 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (lq[i][j] == -1) continue;
      node now;
      now.x = i;
      now.y = j;
      for (int k = 0; k < 8; ++k) {
        node newn;
        newn.x = now.x + fx[k][0];
        newn.y = now.y + fx[k][1];
        if (newn.x > 0 && newn.x <= n && newn.y > 0 && newn.y <= m &&
            lq[newn.x][newn.y] == -1)
          lq[now.x][now.y]++;
      }
    }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      if (lq[i][j] == -1)
        printf("*");
      else
        printf("%d", lq[i][j]);
    printf("\n");
  }
  return 0;
}
