#include <bits/stdc++.h>
using namespace std;
string s[1010];
long long visited[1010][1010], ans[1010][1010], ans1[1010][1010], cnt, cnt1,
    visit[1000010], n, m, vs[10], mx = 0, visited1[1010][1001];
long long dirx[] = {-1, 0, 0, 1};
long long diry[] = {0, -1, 1, 0};
void dfs(long long x, long long y) {
  visited[x][y] = 1;
  long long new_x, new_y;
  for (long long k = 0; k < 4; k++) {
    new_x = x + dirx[k];
    new_y = y + diry[k];
    if (new_x >= 0 && new_y >= 0 && new_x < n && new_y < m) {
      if (s[new_x][new_y] == '.' && !visited[new_x][new_y]) {
        cnt++;
        dfs(new_x, new_y);
      }
    }
  }
  mx = max(mx, cnt);
  ans1[x][y] = cnt1;
}
void dfs1(long long x, long long y) {
  visited1[x][y] = 1;
  ans[x][y] = mx;
  long long new_x, new_y;
  for (long long k = 0; k < 4; k++) {
    new_x = x + dirx[k];
    new_y = y + diry[k];
    if (new_x >= 0 && new_y >= 0 && new_x < n && new_y < m) {
      if (s[new_x][new_y] == '.' && !visited1[new_x][new_y]) {
        dfs1(new_x, new_y);
      }
    }
  }
}
int main() {
  long long i, j, k;
  cin >> n >> m;
  memset(visited, 0, sizeof(visited));
  memset(visited1, 0, sizeof(visited1));
  memset(visit, 0, sizeof(visit));
  memset(vs, 0, sizeof(vs));
  cnt1 = 0;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '.' && !visited[i][j]) {
        cnt = 0;
        mx = 0;
        cnt++;
        dfs(i, j);
        dfs1(i, j);
        cnt1++;
      }
    }
  }
  long long new_x, new_y, sum = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '*') {
        sum = 0;
        for (k = 0; k < 4; k++) {
          new_x = i + dirx[k];
          new_y = j + diry[k];
          if (new_x >= 0 && new_y >= 0 && new_x < n && new_y < m) {
            if (s[new_x][new_y] == '.' && !visit[ans1[new_x][new_y]]) {
              vs[k] = ans1[new_x][new_y];
              visit[ans1[new_x][new_y]] = 1;
              sum += ans[new_x][new_y];
            }
          }
        }
        for (long long k = 0; k < 4; k++) {
          visit[vs[k]] = 0;
        }
        printf("%lld", (sum + 1) % 10);
      } else {
        printf(".");
      }
    }
    printf("\n");
  }
  return 0;
}
