#include <bits/stdc++.h>
using namespace std;
static int n, m;
static char maze[1010][1010];
static int vis[1010][1010];
static int answer[1010][1010];
static int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
static vector<int> ve;
void dfs(int x, int y, int& sum) {
  for (int i = 0; i < 4; i++) {
    int tx = dir[i][0] + x;
    int ty = dir[i][1] + y;
    if (tx < 0 || tx >= n || ty < 0 || ty >= m || vis[tx][ty] ||
        maze[tx][ty] != '.')
      continue;
    vis[tx][ty] = 1;
    ++sum;
    dfs(tx, ty, sum);
    answer[tx][ty] = ve.size();
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%s", maze[i]);
    }
    fill(vis[0], vis[0] + 1000 * 1000, 0);
    int sum = 0;
    ve.clear();
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (maze[i][j] == '*') {
          answer[i][j] = -1;
        } else if (maze[i][j] == '.' && !vis[i][j]) {
          vis[i][j] = 1;
          sum = 1;
          dfs(i, j, sum);
          answer[i][j] = ve.size();
          ve.push_back(sum);
        }
      }
    }
    int tsum = 0;
    set<int> s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (maze[i][j] == '.') {
          printf(".");
          continue;
        }
        tsum = 0;
        s.clear();
        for (int k = 0; k < 4; k++) {
          int tx = dir[k][0] + i;
          int ty = dir[k][1] + j;
          if (tx < 0 || tx >= n || ty < 0 || ty >= m) continue;
          if (s.count(answer[tx][ty]) == 0 && answer[tx][ty] != -1) {
            s.insert(answer[tx][ty]);
            tsum += ve[answer[tx][ty]];
          }
        }
        printf("%d", (tsum + 1) % 10);
      }
      printf("\n");
    }
  }
  return 0;
}
