#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, m;
char M[maxn][maxn];
int vis[maxn][maxn];
int component[maxn * maxn];
int ans[maxn][maxn];
vector<pair<int, int> > wall;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int cpnt = 1;
int dfs(int x, int y) {
  vis[x][y] = cpnt;
  int size = 1;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
    if (M[xx][yy] == '*') continue;
    if (vis[xx][yy]) continue;
    size += dfs(xx, yy);
  }
  return size;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &M[i][j]);
      if (M[i][j] == '*') wall.push_back(make_pair(i, j));
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (M[i][j] == '*') continue;
      if (vis[i][j] == 0) {
        component[cpnt] = dfs(i, j);
        cpnt++;
      }
    }
  }
  memset(ans, -1, sizeof ans);
  for (int i = 0; i < wall.size(); i++) {
    int x = wall[i].first, y = wall[i].second;
    ans[x][y] = 0;
    set<int> ts;
    for (int k = 0; k < 4; k++) {
      int xx = x + dx[k], yy = y + dy[k];
      if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
      if (M[xx][yy] == '*') continue;
      ts.insert(vis[xx][yy]);
    }
    for (set<int>::iterator it = ts.begin(); it != ts.end(); it++) {
      ans[x][y] += component[*it];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (M[i][j] == '*')
        printf("%d", (ans[i][j] + 1) % 10);
      else
        printf(".");
    }
    printf("\n");
  }
  return 0;
}
