#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int s[1000006], p[1000006];
long long int fin(long long int x) {
  if (x == p[x]) return x;
  return x = fin(p[x]);
}
void mak(long long int a, long long int b) {
  if (s[a] < s[b]) swap(a, b);
  s[a] += s[b];
  p[b] = a;
  s[b] = 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, m, x, y;
  cin >> n >> m;
  string a[n];
  for (long long int i = 0; i <= n - 1; i++) cin >> a[i];
  for (long long int i = 0; i <= n - 1; i++)
    for (long long int j = 0; j <= m - 1; j++)
      if (a[i][j] == '.') {
        s[i * m + j] = 1;
        p[i * m + j] = i * m + j;
      }
  for (long long int i = 0; i <= n - 1; i++)
    for (long long int j = 0; j <= m - 1; j++)
      if (a[i][j] == '.') {
        if (i + 1 < n && a[i + 1][j] == '.') {
          x = fin(i * m + j);
          y = fin(m * (i + 1) + j);
          if (x != y) mak(x, y);
        }
        if (j + 1 < m && a[i][j + 1] == '.') {
          x = fin(i * m + j);
          y = fin(m * i + j + 1);
          if (x != y) mak(x, y);
        }
      }
  for (long long int i = 0; i <= n - 1; i++)
    for (long long int j = 0; j <= m - 1; j++)
      if (a[i][j] != '.') {
        set<long long int> se;
        long long int cnt = 1;
        if (i - 1 >= 0 && a[i - 1][j] == '.') se.insert(fin(m * (i - 1) + j));
        if (i + 1 < n && a[i + 1][j] == '.') se.insert(fin(m * (i + 1) + j));
        if (j - 1 >= 0 && a[i][j - 1] == '.') se.insert(fin(m * i + j - 1));
        if (j + 1 < m && a[i][j + 1] == '.') se.insert(fin(m * i + j + 1));
        for (auto it : se) cnt += s[it];
        cnt = cnt % 10;
        char c = cnt + '0';
        a[i][j] = c;
      }
  for (long long int i = 0; i <= n - 1; i++) cout << a[i] << "\n";
}
