#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
char grid[1005][1005];
int R, C;
int visited[1005][1005] = {0};
int cont = 0;
void dfs(int r, int c, int label) {
  if (r < 0 || c < 0 || r >= R || c >= C) return;
  if (visited[r][c] || grid[r][c] == '*') return;
  visited[r][c] = label;
  cont++;
  for (long long int i = (long long int)(0); i < (long long int)(4); i++)
    dfs(r + dr[i], c + dc[i], label);
}
int main() {
  int n, m;
  cin >> n >> m;
  R = n;
  C = m;
  for (int i = 0; i < n; i++) scanf("%s", grid[i]);
  int colors = 1;
  vector<int> tam;
  tam.push_back(0);
  for (long long int i = (long long int)(0); i < (long long int)(n); i++) {
    for (long long int j = (long long int)(0); j < (long long int)(m); j++) {
      if (visited[i][j] or grid[i][j] == '*') continue;
      cont = 0;
      dfs(i, j, colors);
      tam.push_back(cont);
      colors++;
    }
  }
  for (long long int i = (long long int)(0); i < (long long int)(n); i++) {
    for (long long int j = (long long int)(0); j < (long long int)(m); j++) {
      if (grid[i][j] == '*') {
        set<int> ms;
        int ans = 0;
        for (long long int k = (long long int)(0); k < (long long int)(4);
             k++) {
          int r = i + dr[k], c = j + dc[k];
          if (r < 0 || c < 0 || r >= R || c >= C) continue;
          ms.insert(visited[r][c]);
        }
        for (auto x : ms) ans += tam[x] % 10;
        ans = (ans + 1) % 10;
        printf("%d", ans);
      } else
        printf("%c", '.');
    }
    printf("\n");
  }
  return 0;
}
