#include <bits/stdc++.h>
using namespace std;
const int Inf = 1000000000;
const int Maxn = 1005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct pos {
  int first, second, third;
};
int n, m;
int cc[Maxn][Maxn];
int ccs[Maxn * Maxn];
int i2;
string s[Maxn];
int dfs(int i, int j, int c) {
  if (i < 0 || i >= n || j < 0 || j >= m) return -1;
  if (s[i][j] == '*') return -1;
  if (cc[i][j]) return cc[i][j];
  cc[i][j] = c;
  ccs[c]++;
  for (int(d) = 0; (d) < (int)(4); d++) dfs(i + dx[d], j + dy[d], c);
  return c;
}
int main() {
  cin >> n >> m;
  for (int(i) = 0; (i) < (int)(n); i++) cin >> s[i];
  for (int(i) = 0; (i) < (int)(n); i++)
    for (int(ii) = 0; (ii) < (int)(m); ii++) dfs(i, ii, ++i2);
  for (int(i) = 0; (i) < (int)(n); i++) {
    for (int(ii) = 0; (ii) < (int)(m); ii++) {
      if (s[i][ii] == '*') {
        set<int> f;
        for (int(d) = 0; (d) < (int)(4); d++)
          f.insert(dfs(i + dx[d], ii + dy[d], 0));
        int su = 1;
        for (set<int>::iterator it = f.begin(); it != f.end(); it++)
          if (*it > -1) su += ccs[*it];
        cout << su % 10;
      } else
        cout << '.';
    }
    cout << endl;
  }
  return 0;
}
