#include <bits/stdc++.h>
using namespace std;
int n, m, step = 0, sum;
char f[1005][1005];
int ans[1005][1005];
bool vis[1005][1005];
int moves[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
map<int, int> mp;
set<int> se;
set<int>::iterator it;
void bfs(int x, int y) {
  vis[x][y] = true;
  ans[x][y] = step;
  for (int k = 0; k < 4; k++) {
    int X = x + moves[k][0];
    int Y = y + moves[k][1];
    if (X >= 1 && X <= n && Y >= 1 && Y <= m && f[X][Y] == '.' && !vis[X][Y]) {
      sum++;
      bfs(X, Y);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  getchar();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%c", &f[i][j]);
      ans[i][j] = 0;
    }
    getchar();
  }
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (f[i][j] == '.' && !vis[i][j]) {
        sum = 1;
        step++;
        bfs(i, j);
        mp[step] = sum;
      }
    }
  }
  mp[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (f[i][j] == '.') {
        printf(".");
      } else {
        if (i - 1 >= 1) se.insert(ans[i - 1][j]);
        if (i + 1 <= n) se.insert(ans[i + 1][j]);
        if (j - 1 >= 1) se.insert(ans[i][j - 1]);
        if (j + 1 <= m) se.insert(ans[i][j + 1]);
        int S = 1;
        for (it = se.begin(); it != se.end(); it++) {
          S += mp[*it];
        }
        se.clear();
        S %= 10;
        printf("%d", S);
      }
    }
    printf("\n");
  }
  return 0;
}
