#include <bits/stdc++.h>
using namespace std;
char grid[1004][1004];
int N, M, sizef[1000010], fl[1004][1004];
void dfs(int i, int j, int num) {
  if (i <= 0 || j <= 0 || i > N || j > M) return;
  if (fl[i][j] == num) return;
  fl[i][j] = num;
  if (grid[i][j] == '*') return;
  dfs(i + 1, j, num);
  dfs(i - 1, j, num);
  dfs(i, j + 1, num);
  dfs(i, j - 1, num);
}
bool valid(int i, int j) {
  if (i < 0 || j < 0 || i > N || j > M) return false;
  if (grid[i][j] == '*') return false;
  return true;
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) scanf("%s", grid[i] + 1);
  memset(sizef, 0, sizeof(sizef));
  memset(fl, 0, sizeof(fl));
  int cnt = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (fl[i][j] == 0 && grid[i][j] == '.') {
        dfs(i, j, cnt);
        cnt++;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (grid[i][j] == '.') sizef[fl[i][j]]++;
    }
  }
  int ans = 0;
  set<int> s;
  set<int>::iterator it;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (grid[i][j] == '*') {
        s.clear();
        ans = 0;
        if (valid(i + 1, j)) s.insert(fl[i + 1][j]);
        if (valid(i - 1, j)) s.insert(fl[i - 1][j]);
        if (valid(i, j + 1)) s.insert(fl[i][j + 1]);
        if (valid(i, j - 1)) s.insert(fl[i][j - 1]);
        it = s.begin();
        while (it != s.end()) {
          ans = ans + sizef[(*it)];
          it++;
        }
        ans++;
        ans = ans % 10;
        printf("%d", ans);
      } else
        printf(".");
    }
    printf("\n");
  }
  return 0;
}
