#include <bits/stdc++.h>
using namespace std;
int r, c, numCC, belongTo[1003][1003], size[1000003];
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
char maps[1003][1003];
bool ok(int uc, int ur) {
  return (uc >= 1 && uc <= c && ur >= 1 && ur <= r && maps[uc][ur] == '.');
}
int DFS(int uc, int ur, int num) {
  belongTo[uc][ur] = num;
  int ret = 1;
  for (int i = 0; i < 4; i++) {
    int vc = uc + dc[i], vr = ur + dr[i];
    if (ok(vc, vr) && belongTo[vc][vr] == -1) ret += DFS(vc, vr, num);
  }
  return ret;
}
int main() {
  cin >> r >> c;
  for (int j = 1; j <= r; j++)
    for (int i = 1; i <= c; i++) cin >> maps[i][j];
  numCC = 0;
  memset(belongTo, -1, sizeof(belongTo));
  for (int j = 1; j <= r; j++) {
    for (int i = 1; i <= c; i++) {
      if (maps[i][j] == '.' && belongTo[i][j] == -1)
        size[++numCC] = DFS(i, j, numCC);
    }
  }
  for (int j = 1; j <= r; j++) {
    for (int i = 1; i <= c; i++) {
      if (maps[i][j] == '.')
        cout << maps[i][j];
      else {
        int tot = 1;
        set<int> uniq;
        for (int dir = 0; dir < 4; dir++) {
          int ii = i + dc[dir], jj = j + dr[dir];
          if (ok(ii, jj)) uniq.insert(belongTo[ii][jj]);
        }
        for (set<int>::iterator it = uniq.begin(); it != uniq.end(); it++)
          tot += size[*it];
        cout << tot % 10;
      }
    }
    cout << endl;
  }
}
