#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int mod = 1e9 + 7;
int n, m, used[N][N], clr[N][N], cnt[N * N], cmp;
char second[N][N];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool can(int x, int y) {
  return (x >= 0 && y >= 0 && x < n && y < m && second[x][y] == '.');
}
void dfs(int x, int y, int cmp) {
  used[x][y] = 1;
  clr[x][y] = cmp;
  cnt[cmp]++;
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i], yy = y + dy[i];
    if (can(xx, yy) && !used[xx][yy]) dfs(xx, yy, cmp);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("\n%s", second[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (second[i][j] == '.' && !used[i][j]) {
        cmp++;
        dfs(i, j, cmp);
      }
  for (int i = 0; i < n; ++i) {
    string res = "";
    for (int j = 0; j < m; ++j) {
      if (second[i][j] == '.')
        res += '.';
      else {
        vector<int> colors;
        int sum = 1;
        for (int k = 0; k < 4; ++k) {
          int x = dx[k] + i, y = dy[k] + j;
          if (can(x, y)) {
            bool ok = 1;
            for (int w : colors)
              if (w == clr[x][y]) ok = 0;
            if (ok) sum += cnt[clr[x][y]], colors.push_back(clr[x][y]);
          }
        }
        res += char(sum % 10 + '0');
      }
    }
    printf("%s\n", res.c_str());
  }
  return 0;
}
