#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
map<pair<long long, long long>, long long> mp;
long long p[N * N], sz[N * N];
void init() {
  for (long long i = 0; i < N * N; i++) p[i] = i, sz[i] = 1;
  long long cnt = 0;
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++) mp[{i, j}] = cnt++;
}
long long dsu_parent(long long node) {
  if (p[node] == node) return node;
  return p[node] = dsu_parent(p[node]);
}
void dsu_union(long long a, long long b) {
  a = dsu_parent(a);
  b = dsu_parent(b);
  if (a == b) return;
  if (sz[a] < sz[b]) swap(a, b);
  p[b] = a;
  sz[a] += sz[b];
}
char arr[N][N];
bool vis[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  init();
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == '*' || vis[i][j]) continue;
      pair<long long, long long> node = {i, j};
      queue<pair<long long, long long> > q;
      q.push(node);
      vis[i][j] = 1;
      while (!q.empty()) {
        long long x = q.front().first;
        long long y = q.front().second;
        dsu_union(mp[q.front()], mp[node]);
        q.pop();
        if (x + 1 < n && arr[x + 1][y] == '.' && !vis[x + 1][y])
          q.push({x + 1, y}), vis[x + 1][y] = 1;
        if (x - 1 >= 0 && arr[x - 1][y] == '.' && !vis[x - 1][y])
          q.push({x - 1, y}), vis[x - 1][y] = 1;
        if (y + 1 < m && arr[x][y + 1] == '.' && !vis[x][y + 1])
          q.push({x, y + 1}), vis[x][y + 1] = 1;
        if (y - 1 >= 0 && arr[x][y - 1] == '.' && !vis[x][y - 1])
          q.push({x, y - 1}), vis[x][y - 1] = 1;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == '.') {
        cout << ".";
        continue;
      }
      long long ans = 1;
      set<long long> candidates;
      if (i + 1 < n && arr[i + 1][j] != '*') {
        auto pr = dsu_parent(mp[{i + 1, j}]);
        if (!candidates.count(pr)) ans += sz[pr];
        candidates.insert(pr);
      }
      if (i - 1 >= 0 && arr[i - 1][j] != '*') {
        auto pr = dsu_parent(mp[{i - 1, j}]);
        if (!candidates.count(pr)) ans += sz[pr];
        candidates.insert(pr);
      }
      if (j + 1 < m && arr[i][j + 1] != '*') {
        auto pr = dsu_parent(mp[{i, j + 1}]);
        if (!candidates.count(pr)) ans += sz[pr];
        candidates.insert(pr);
      }
      if (j - 1 >= 0 && arr[i][j - 1] != '*') {
        auto pr = dsu_parent(mp[{i, j - 1}]);
        if (!candidates.count(pr)) ans += sz[pr];
        candidates.insert(pr);
      }
      cout << ans % 10;
    }
    cout << "\n";
  }
}
