#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const int N = 1002;
char a[N][N];
int n, m;
int sh[N][N];
int cnt[N * N];
char ans[N][N];
int dfs(int c, int b, int t) {
  sh[c][b] = t;
  int v = 1;
  for (int i = 0; i < 4; ++i) {
    int x = c + dx[i], y = b + dy[i];
    if (x < 0 || y < 0 || x >= n || y >= m || sh[x][y] || a[x][y] != '.')
      continue;
    v += dfs(x, y, t);
  }
  return v;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) scanf("%s", a[i]);
  int x = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '.' && !sh[i][j]) {
        cnt[x] = dfs(i, j, x);
        x++;
      }
  set<int> st;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (a[i][j] == '*') {
        st.clear();
        int tmp = 1;
        for (int k = 0; k < 4; ++k) {
          int x = i + dx[k], y = j + dy[k];
          if (x < 0 || y < 0 || x >= n || y >= m || !sh[x][y]) continue;
          if (st.find(sh[x][y]) == st.end()) {
            st.insert(sh[x][y]);
            tmp += cnt[sh[x][y]];
          }
        }
        tmp %= 10;
        ans[i][j] = (char)(tmp + '0');
      } else
        ans[i][j] = '.';
  for (int i = 0; i < n; ++i) printf("%s\n", ans[i]);
  return 0;
}
