#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
char a[1002][1002];
char ans[1002][1002];
int vis[1002][1002], n, m, tot[N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void dfs(int x, int y, int col) {
  vis[x][y] = col;
  tot[col]++;
  for (int i = 0; i < 4; i++) {
    int x1 = x + dx[i];
    int y1 = y + dy[i];
    if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m && a[x1][y1] == '.' &&
        !vis[x1][y1]) {
      dfs(x1, y1, col);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
  }
  int col = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.' && !vis[i][j]) {
        dfs(i, j, col);
        col++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '*') {
        set<int> s;
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '.') {
            s.insert(vis[x][y]);
          }
        }
        int ans1 = 1;
        for (auto &it : s) {
          ans1 += tot[it];
          ans1 %= 10;
        }
        ans[i][j] = '0' + ans1;
      } else {
        ans[i][j] = a[i][j];
      }
    }
    ans[i][m] = '\0';
  }
  for (int i = 0; i < n; i++) {
    printf("%s\n", ans[i]);
  }
  return 0;
}
