#include <bits/stdc++.h>
using namespace std;
int n, m, g[1005][1005], c[1005][1005], ch[1005][1005], ans[1005][1005],
    k = 1, dix[4] = {0, 0, 1, -1}, diy[4] = {1, -1, 0, 0};
char tb[1005][1005];
int main() {
  int co;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", tb[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (tb[i][j] == '.' && !ch[i][j]) {
        co = 0;
        queue<pair<int, int>> q;
        q.push(make_pair(i, j));
        while (!q.empty()) {
          int x = q.front().first, y = q.front().second;
          q.pop();
          if (ch[x][y]) continue;
          co++;
          ch[x][y] = 1;
          g[x][y] = k;
          for (int z = 0; z < 4; z++) {
            int a = x + dix[z], b = y + diy[z];
            if ((a >= 0 && a < n) && (b >= 0 && b < m))
              if (tb[a][b] == '.' && !ch[a][b]) q.push(make_pair(a, b));
          }
        }
        k++;
        q.push(make_pair(i, j));
        while (!q.empty()) {
          int x = q.front().first, y = q.front().second;
          q.pop();
          if (c[x][y] > 0) continue;
          c[x][y] = co;
          for (int z = 0; z < 4; z++) {
            int a = x + dix[z], b = y + diy[z];
            if ((a >= 0 && a < n) && (b >= 0 && b < m))
              if (tb[a][b] == '.' && c[a][b] == 0) q.push(make_pair(a, b));
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (tb[i][j] == '.')
        ans[i][j] = '.';
      else {
        int k = 1;
        set<int> s;
        for (int z = 0; z < 4; z++) {
          int x = i + dix[z], y = j + diy[z];
          if ((x >= 0 && x < n) && (y >= 0 && y < m))
            if (tb[x][y] == '.' && s.count(g[x][y]) == 0) {
              k += c[x][y];
              s.insert(g[x][y]);
            }
        }
        s.clear();
        k %= 10;
        ans[i][j] = k + '0';
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%c", ans[i][j]);
    printf("\n");
  }
}
