#include <bits/stdc++.h>
using namespace std;
int A[2000][2000];
int EXP[2000][2000];
map<int, int> sizes;
int n, m;
int bfs_paint(int x, int y, int color) {
  queue<pair<int, int> > q;
  EXP[x][y] = color;
  int sum = 1;
  q.push(make_pair((x), (y)));
  while (!q.empty()) {
    pair<int, int> s = q.front();
    q.pop();
    for (long long(i) = (-1); (i) < (2); (i)++) {
      for (long long(j) = (-1); (j) < (2); (j)++) {
        if (i * j != 0) continue;
        x = s.first + i;
        y = s.second + j;
        if (x >= 0 && x < n && y >= 0 && y < m && !A[x][y] && !EXP[x][y]) {
          EXP[x][y] = color;
          sum++;
          q.push(make_pair((x), (y)));
        }
      }
    }
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m;
  for (long long(i) = (0); (i) < (n); (i)++) {
    for (long long(j) = (0); (j) < (m); (j)++) {
      char aux;
      cin >> aux;
      A[i][j] = aux == '*' ? 1 : 0;
    }
  }
  for (long long(i) = (0); (i) < (2000); (i)++)
    for (long long(j) = (0); (j) < (2000); (j)++) EXP[i][j] = 0;
  int color = 1;
  for (long long(i) = (0); (i) < (n); (i)++) {
    for (long long(j) = (0); (j) < (m); (j)++) {
      if (A[i][j] == 0 && !EXP[i][j]) {
        int s = bfs_paint(i, j, color);
        sizes[color] = s;
        color++;
      }
    }
  }
  for (long long(i) = (0); (i) < (n); (i)++) {
    string cad;
    for (long long(j) = (0); (j) < (m); (j)++) {
      if (A[i][j]) {
        int s = 1;
        set<int> ids;
        for (long long(i_o) = (-1); (i_o) < (2); (i_o)++) {
          for (long long(j_o) = (-1); (j_o) < (2); (j_o)++) {
            if (i_o * j_o != 0) continue;
            int x = i + i_o, y = j + j_o;
            if (x >= 0 && x < n && y >= 0 && y < m && EXP[x][y]) {
              ids.insert(EXP[x][y]);
            }
          }
        }
        for (std::set<int>::iterator it = ids.begin(); it != ids.end(); ++it)
          s += sizes[*it];
        char aux = ('0' + s % 10);
        cad.push_back(aux);
      } else {
        cad.push_back('.');
      }
    }
    cout << cad << endl;
  }
  return 0;
}
