#include <bits/stdc++.h>
using namespace std;
struct xjy {
  int x;
  int y;
};
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
char mmap[1111][1111];
xjy pre[1111][1111];
int num[1111][1111];
xjy findx(xjy xx) {
  xjy r = xx;
  while (pre[r.x][r.y].x != r.x || pre[r.x][r.y].y != r.y) {
    r = pre[r.x][r.y];
  }
  xjy i = xx, j;
  while (pre[i.x][i.y].x != r.x || pre[i.x][i.y].y != r.y) {
    j = pre[i.x][i.y];
    pre[i.x][i.y] = r;
    i = j;
  }
  return r;
}
void join(xjy xx, xjy yy) {
  xjy p1 = findx(xx);
  xjy p2 = findx(yy);
  if (p1.x != p2.x || p1.y != p2.y) {
    pre[p1.x][p1.y] = p2;
    num[p2.x][p2.y] += num[p1.x][p1.y];
    num[p1.x][p1.y] = 0;
  }
}
int main() {
  for (int i = 0; i <= 1001; i++)
    for (int j = 0; j <= 1001; j++) {
      xjy mid;
      mid.x = i;
      mid.y = j;
      pre[i][j] = mid;
      num[i][j] = 0;
      mmap[i][j] = '*';
    }
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char c;
      scanf(" %c", &c);
      if (c == '.') {
        mmap[i][j] = c;
        num[i][j] = 1;
      } else
        mmap[i][j] = c;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (mmap[i][j] == '.') {
        xjy mid;
        mid.x = i;
        mid.y = j;
        xjy midmid;
        for (int ii = 0; ii < 4; ii++) {
          midmid.x = mid.x + dir[ii][0];
          midmid.y = mid.y + dir[ii][1];
          if (mmap[midmid.x][midmid.y] == '.') {
            join(mid, midmid);
          }
        }
      }
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mmap[i][j] == '*') {
        int sum = 0;
        xjy mid;
        mid.x = i;
        mid.y = j;
        vector<xjy> sss;
        for (int ii = 0; ii < 4; ii++) {
          xjy midmid;
          midmid.x = mid.x + dir[ii][0];
          midmid.y = mid.y + dir[ii][1];
          if (mmap[midmid.x][midmid.y] == '.') {
            sum = 0;
            midmid = findx(midmid);
            if (sss.size() == 0)
              sss.push_back(midmid);
            else {
              int eend = sss.size();
              int flag = 1;
              for (int it = 0; it != eend; it++)
                if (midmid.x == sss[it].x && midmid.y == sss[it].y) {
                  flag = 0;
                }
              if (flag) sss.push_back(midmid);
            }
          }
        }
        for (int it = 0; it != sss.size(); it++) {
          xjy midmidmid = findx(sss[it]);
          int midx = midmidmid.x;
          int midy = midmidmid.y;
          sum += num[midx][midy];
        }
        printf("%d", (sum + 1) % 10);
      } else
        printf("%c", mmap[i][j]);
    }
    printf("\n");
  }
}
