#include <bits/stdc++.h>
using namespace std;
string getstr() {
  char c[1001];
  scanf("%s", c);
  return c;
}
int n, m;
vector<string> v;
vector<vector<int> > sz, b;
int getsz(int i, int j) {
  if (v[i][j] == '*' || sz[i][j]) return 0;
  sz[i][j] = 1;
  return getsz(i + 1, j) + getsz(i - 1, j) + getsz(i, j + 1) + getsz(i, j - 1) +
         1;
}
void setsz(int i, int j, int szz, int id) {
  if (v[i][j] == '*' || b[i][j] == id) return;
  sz[i][j] = szz;
  b[i][j] = id;
  setsz(i + 1, j, szz, id), setsz(i - 1, j, szz, id), setsz(i, j + 1, szz, id),
      setsz(i, j - 1, szz, id);
}
int main() {
  scanf("%d %d", &n, &m);
  v.resize(n + 2, string(m + 2, '*'));
  sz.resize(n + 2, vector<int>(m + 2, 0));
  b.resize(n + 2, vector<int>(m + 2, 0));
  for (int i = (1); i <= (n); ++i) {
    v[i] = "*" + getstr() + "*";
  }
  int id = 0;
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) {
      int k = getsz(i, j);
      if (k) setsz(i, j, k, ++id);
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) {
      if (v[i][j] == '.') continue;
      map<int, int> q;
      q[b[i + 1][j]] = sz[i + 1][j];
      q[b[i - 1][j]] = sz[i - 1][j];
      q[b[i][j + 1]] = sz[i][j + 1];
      q[b[i][j - 1]] = sz[i][j - 1];
      int r = 1;
      for (auto k : q) r += k.second;
      v[i][j] = '0' + (r % 10);
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) {
      putchar(v[i][j]);
    }
    putchar('\n');
  }
}
