#include <bits/stdc++.h>
using namespace std;
void fre() { freopen("t.txt", "r", stdin); }
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int dir[4][2] = {0, -1, 0, 1, -1, 0, 1, 0};
char mp[1005][1005];
int _set[1005][1005], cnt[1000010], tol, n, m;
int dfs(int x, int y, int id) {
  int xx, yy, i;
  cnt[id]++;
  _set[x][y] = id;
  for (i = 0; i < 4; ++i) {
    xx = x + dir[i][0];
    yy = y + dir[i][1];
    if (xx < 0 || yy < 0 || xx >= n || yy >= m || mp[xx][yy] == '*' ||
        _set[xx][yy])
      continue;
    dfs(xx, yy, id);
  }
}
int calc(int x, int y) {
  set<int> st;
  int xx, yy, i, ans = 0;
  for (i = 0; i < 4; ++i) {
    xx = x + dir[i][0];
    yy = y + dir[i][1];
    if (xx < 0 || yy < 0 || xx >= n || yy >= m || mp[xx][yy] == '*') continue;
    if (!st.count(_set[xx][yy]))
      ans += cnt[_set[xx][yy]], st.insert(_set[xx][yy]);
  }
  return (ans + 1) % 10;
}
int main() {
  int i, j;
  tol = 1;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; ++i) {
    scanf("%s", mp[i]);
  }
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (_set[i][j] || mp[i][j] == '*') continue;
      dfs(i, j, tol);
      tol++;
    }
  }
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (mp[i][j] == '.')
        printf(".");
      else
        printf("%d", calc(i, j));
    }
    puts("");
  }
}
