#include <bits/stdc++.h>
using namespace std;
long long m, n, A[1005][1005], B[1005][1005], C[1000005];
long long dfs(long long x, long long y, long long stamp) {
  B[x][y] = stamp;
  if (A[x - 1][y] == 1 && B[x - 1][y] == 0) dfs(x - 1, y, stamp);
  if (A[x + 1][y] == 1 && B[x + 1][y] == 0) dfs(x + 1, y, stamp);
  if (A[x][y - 1] == 1 && B[x][y - 1] == 0) dfs(x, y - 1, stamp);
  if (A[x][y + 1] == 1 && B[x][y + 1] == 0) dfs(x, y + 1, stamp);
}
int main() {
  string s;
  cin >> m >> n;
  for (long long i = 1; i <= m; i++) {
    cin >> s;
    for (long long j = 1; j <= n; j++)
      if (s[j - 1] == '.')
        A[i][j] = 1;
      else
        A[i][j] = 0;
  }
  long long stamp = 1;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      if (B[i][j] == 0 && A[i][j] == 1) {
        dfs(i, j, stamp);
        stamp++;
      }
    }
  }
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      C[B[i][j]]++;
    }
  }
  C[0] = 0;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      if (A[i][j] == 1)
        cout << ".";
      else {
        long long count = 0;
        set<long long> myset;
        myset.insert(B[i + 1][j]);
        myset.insert(B[i - 1][j]);
        myset.insert(B[i][j + 1]);
        myset.insert(B[i][j - 1]);
        set<long long>::iterator it;
        for (it = myset.begin(); it != myset.end(); ++it) count += C[*it];
        cout << ((count + 1) % 10);
      }
    }
    cout << endl;
  }
  return 0;
}
