#include <bits/stdc++.h>
using namespace std;
array<int, 4> toi = {-1, 0, 1, 0}, toj = {0, 1, 0, -1};
int n, m;
int component;
vector<string> A;
vector<vector<bool>> visited;
vector<vector<int>> belong;
vector<int> ret;
void Read() {
  cin >> n >> m;
  A = vector<string>(n);
  for (int i = 0; i < n; ++i) cin >> A[i];
}
bool isValid(int i, int j) {
  return i >= 0 && j >= 0 && i < n && j < m && A[i][j] != '*' &&
         visited[i][j] == 0;
}
void dfs(int i, int j) {
  visited[i][j] = 1;
  belong[i][j] = component;
  ret[component] += 1;
  for (int k = 0; k < 4; ++k) {
    int ni = toi[k] + i, nj = toj[k] + j;
    if (isValid(ni, nj) == 0) continue;
    dfs(ni, nj);
  }
}
void Build() {
  visited = vector<vector<bool>>(n, vector<bool>(m));
  belong = vector<vector<int>>(n, vector<int>(m));
  ret = vector<int>(n * m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (isValid(i, j) == false) continue;
      dfs(i, j);
      ++component;
    }
}
char getans(int i, int j) {
  auto good = [](int ii, int jj) {
    return ii >= 0 && jj >= 0 && ii < n && jj < m;
  };
  int foo = 1;
  set<int> comps;
  for (int k = 0; k < 4; ++k) {
    int ni = toi[k] + i;
    int nj = toj[k] + j;
    if (good(ni, nj) == false || A[ni][nj] == '*') continue;
    int where = belong[ni][nj];
    if (comps.find(where) != comps.end()) continue;
    comps.insert(where);
    foo += ret[where];
  }
  foo %= 10;
  foo += '0';
  return foo;
}
void Solve() {
  for (int i = 0; i < n; ++i) {
    string result;
    for (int j = 0; j < m; ++j) {
      if (A[i][j] == '.') {
        result += '.';
        continue;
      }
      result += getans(i, j);
    }
    cout << result << '\n';
  }
}
int main() {
  Read();
  Build();
  Solve();
  return 0;
}
