#include <bits/stdc++.h>
const int Inf = 2 * 1000 * 1000 * 1000;
long long LINF = (long long)4e18;
using namespace std;
const int maxn = 1005;
int n, m;
int used[maxn][maxn];
char a[maxn][maxn];
int b[maxn][maxn];
bool ok(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
set<pair<int, int>> wall;
int sz;
void dfs(int x, int y) {
  sz++;
  used[x][y] = 1;
  for (int dx = x - 1; dx <= x + 1; dx++) {
    for (int dy = y - 1; dy <= y + 1; dy++) {
      if (x != dx && y != dy) continue;
      if (ok(dx, dy)) {
        if (a[dx][dy] == '*') {
          wall.insert({dx, dy});
          continue;
        }
        if (used[dx][dy]) continue;
        dfs(dx, dy);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (used[i][j] || a[i][j] == '*') continue;
      wall.clear();
      sz = 0;
      dfs(i, j);
      for (auto &p : wall) {
        b[p.first][p.second] += sz;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.')
        cout << '.';
      else
        cout << (b[i][j] + 1) % 10;
    }
    cout << '\n';
  }
  return 0;
}
