#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
char mmap[1111][1111];
int book[1111][1111];
struct xjy {
  int x;
  int y;
  int step;
  bool operator<(const xjy &r) const { return step > r.step; }
};
int sum[11111111];
void bfs(int x, int y, int cnt) {
  xjy mid;
  mid.x = x;
  mid.y = y;
  mid.step = 0;
  priority_queue<xjy> q;
  q.push(mid);
  int ans = 0;
  while (!q.empty()) {
    mid = q.top();
    q.pop();
    if (book[mid.x][mid.y]) continue;
    book[mid.x][mid.y] = cnt;
    ans++;
    xjy midmid;
    for (int i = 0; i < 4; i++) {
      midmid.x = mid.x + dir[i][0];
      midmid.y = mid.y + dir[i][1];
      midmid.step = mid.step + 1;
      if (!book[midmid.x][midmid.y] && mmap[midmid.x][midmid.y] == '.') {
        q.push(midmid);
      }
    }
  }
  sum[cnt] = ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= m + 1; j++) mmap[i][j] = '*';
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mmap[i][j];
    }
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mmap[i][j] == '.') {
        if (!book[i][j]) {
          bfs(i, j, cnt++);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mmap[i][j] == '.')
        cout << ".";
      else {
        int ansum = 0;
        xjy mid;
        mid.x = i;
        mid.y = j;
        int sset[5];
        int ccnt = 0;
        for (int k = 0; k <= 4; k++) sset[k] = 0;
        for (int k = 0; k < 4; k++) {
          xjy midmid;
          midmid.x = mid.x + dir[k][0];
          midmid.y = mid.y + dir[k][1];
          int flag = 1;
          for (int kk = 0; kk < 4; kk++) {
            if (sset[kk] == book[midmid.x][midmid.y]) flag = 0;
          }
          if (flag) sset[ccnt++] = book[midmid.x][midmid.y];
        }
        for (int k = 0; k < ccnt; k++) {
          ansum += sum[sset[k]];
        }
        cout << (ansum + 1) % 10;
      }
    }
    cout << endl;
  }
}
