#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, M;
string S[1001];
int label[1001][1001];
int sticker = 1;
int siz[1000001];
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void dfs(int x, int y) {
  if (x < 0 || x >= N || y < 0 || y >= M || label[x][y] != 0 || S[x][y] == '*')
    return;
  label[x][y] = sticker;
  siz[sticker]++;
  for (int i = 0; i < 4; i++) dfs(x + dir[i][0], y + dir[i][1]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      if (S[i][j] == '.' && label[i][j] == 0) {
        dfs(i, j);
        sticker++;
      }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i][j] == '.')
        cout << '.';
      else {
        int ans = 0;
        set<int> labs;
        for (int k = 0; k < 4; k++) {
          int newx = i + dir[k][0];
          int newy = j + dir[k][1];
          if (newx >= 0 && newx < N && newy >= 0 && newy < M &&
              !labs.count(label[newx][newy])) {
            labs.insert(label[newx][newy]);
            ans += siz[label[newx][newy]];
          }
        }
        cout << (ans + 1) % 10;
      }
    }
    cout << endl;
  }
  return 0;
}
