#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[1111];
int vis[1111][1111];
int cnt;
int num;
void f(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m) return;
  if (vis[x][y] != -1) return;
  if (s[x][y] == '*') return;
  vis[x][y] = cnt;
  ++num;
  f(x - 1, y);
  f(x + 1, y);
  f(x, y - 1);
  f(x, y + 1);
}
int calc[11111111];
bool gett[11111111];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (vis[i][j] == -1) num = 0, f(i, j), calc[cnt] = num, ++cnt;
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '.')
        cout << '.';
      else {
        int nn = 1;
        if (i && !gett[vis[i - 1][j]])
          nn += calc[vis[i - 1][j]], gett[vis[i - 1][j]] = 1;
        if (j && !gett[vis[i][j - 1]])
          nn += calc[vis[i][j - 1]], gett[vis[i][j - 1]] = 1;
        if (i + 1 < n && !gett[vis[i + 1][j]])
          nn += calc[vis[i + 1][j]], gett[vis[i + 1][j]] = 1;
        if (j + 1 < m && !gett[vis[i][j + 1]])
          nn += calc[vis[i][j + 1]], gett[vis[i][j + 1]] = 1;
        nn %= 10;
        cout << char(nn + '0');
        if (i && gett[vis[i - 1][j]])
          nn += calc[vis[i - 1][j]], gett[vis[i - 1][j]] = 0;
        if (j && gett[vis[i][j - 1]])
          nn += calc[vis[i][j - 1]], gett[vis[i][j - 1]] = 0;
        if (i + 1 < n && gett[vis[i + 1][j]])
          nn += calc[vis[i + 1][j]], gett[vis[i + 1][j]] = 0;
        if (j + 1 < m && gett[vis[i][j + 1]])
          nn += calc[vis[i][j + 1]], gett[vis[i][j + 1]] = 0;
      }
      if (j == m - 1) cout << "\n";
    }
  return 0;
}
