#include <bits/stdc++.h>
using namespace std;
int n, m, cl[int(1e3) + 1][int(1e3) + 1], col, sz[int(1e6) + 1], ans;
char c[int(1e3) + 1][int(1e3) + 1];
set<int> st;
bool in(int x, int y) { return ((0 <= x && x < n) && (0 <= y && y < m)); }
void dfs(int x, int y) {
  cl[x][y] = col;
  sz[col]++;
  for (int i = -1; i < 2; i++) {
    for (int j = -1; j < 2; j++) {
      if (abs(i) + abs(j) == 1 && in(x + i, y + j) && c[x + i][y + j] == '.' &&
          cl[x + i][y + j] == 0) {
        dfs(x + i, y + j);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (c[i][j] == '.' && cl[i][j] == 0) {
        col++;
        dfs(i, j);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (c[i][j] == '*') {
        for (int x = -1; x < 2; ++x) {
          for (int y = -1; y < 2; ++y) {
            if (abs(x) + abs(y) == 1 && in(i + x, j + y) &&
                c[i + x][j + y] == '.') {
              st.insert(cl[i + x][j + y]);
            }
          }
        }
        for (auto it : st) {
          ans += sz[it];
        }
        st.clear();
        cout << (1 + ans) % 10;
        ans = 0;
      } else {
        cout << ".";
      }
    }
    cout << "\n";
  }
  return 0;
}
