#include <bits/stdc++.h>
using namespace std;
int n, m;
string A[1005], W[1005];
int color[1005][1005];
int sz[1005 * 1005];
int C = 1;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool good(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m || A[x][y] == '*') return 0;
  return 1;
}
void dfs(int x, int y) {
  color[x][y] = C;
  sz[C]++;
  for (int k = 0; k < 4; k++) {
    int nx = x + dx[k], ny = y + dy[k];
    if (good(nx, ny) && color[nx][ny] == 0) dfs(nx, ny);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    W[i] = A[i];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (color[i][j] == 0 && A[i][j] == '.') {
        dfs(i, j);
        C++;
      }
      W[i][j] = '.';
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (A[i][j] != '*') continue;
      int t = 1;
      set<int> S;
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (good(nx, ny)) S.insert(color[nx][ny]);
      }
      for (auto it = S.begin(); it != S.end(); it++) {
        t += sz[*it];
      }
      t %= 10;
      W[i][j] = char('0' + t);
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << W[i][j];
    cout << "\n";
  }
  return 0;
}
