#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, rp;
bool can[1010][1010];
bool vis[1010][1010];
int cc[1010][1010];
int an[1010][1010];
vector<int> siz;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
inline bool check(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) {
    if (!vis[x][y] && can[x][y]) return 1;
  }
  return 0;
}
inline void getstr(int x) {
  char ch;
  for (int i = 0; i < m; i++) {
    ch = getchar();
    if (ch == '.') can[x][i] = 1;
  }
  ch = getchar();
}
void dfs(int x, int y, int col) {
  cnt++;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (check(xx, yy)) {
      dfs(xx, yy, col);
    }
  }
  cc[x][y] = col;
}
int main() {
  cin >> n >> m;
  char ch = getchar();
  for (int i = 0; i < n; i++) getstr(i);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && can[i][j]) {
        cnt = 0;
        dfs(i, j, rp);
        siz.push_back(cnt);
        rp++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!can[i][j]) {
        int ans = 1;
        set<int> st;
        for (int k = 0; k < 4; k++) {
          int xx = i + dx[k], yy = j + dy[k];
          if (xx >= 0 && xx < n && yy >= 0 && yy < m) {
            if (!can[xx][yy]) continue;
            int bel = cc[xx][yy];
            if (st.count(bel)) continue;
            st.insert(bel);
            ans += siz[bel];
          }
        }
        an[i][j] = ans % 10;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!can[i][j]) {
        putchar(an[i][j] + '0');
      } else {
        putchar('.');
      }
    }
    putchar('\n');
  }
  return 0;
}
