#include <bits/stdc++.h>
using namespace std;
int n, m;
char ori_matrix[1010][1010];
int dep_matrix[1010][1010];
char ans_matrix[1010][1010];
bool vis[1010][1010];
int dep_num[1010 * 1010];
int depth;
int dir_x[] = {0, 0, 1, -1};
int dir_y[] = {1, -1, 0, 0};
void dfs(int x, int y, int depth) {
  if (x < 1 || x > n || y < 1 || y > m) return;
  if (vis[x][y]) return;
  vis[x][y] = 1;
  if (ori_matrix[x][y] == '.') {
    dep_matrix[x][y] = depth;
    dep_num[depth]++;
    for (int i = 0; i < 4; i++) {
      dfs(x + dir_x[i], y + dir_y[i], depth);
    }
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%s", ori_matrix[i] + 1);
    memset(vis, 0, sizeof(vis));
    memset(dep_num, 0, sizeof(dep_num));
    memset(dep_matrix, 0, sizeof(dep_matrix));
    depth = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (ori_matrix[i][j] == '.' && !vis[i][j]) {
          dfs(i, j, depth);
          depth++;
        }
      }
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) ans_matrix[i][j] = ori_matrix[i][j];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (ori_matrix[i][j] == '*') {
          set<int> st;
          st.insert(dep_matrix[i - 1][j]);
          st.insert(dep_matrix[i + 1][j]);
          st.insert(dep_matrix[i][j - 1]);
          st.insert(dep_matrix[i][j + 1]);
          int tmp = 0;
          for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
            tmp += dep_num[(*it)];
          }
          tmp = (tmp + 1) % 10;
          ans_matrix[i][j] = '0' + tmp;
        }
      }
    }
    for (int i = 1; i <= n; i++) printf("%s\n", ans_matrix[i] + 1);
  }
  return 0;
}
