#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1005, maxm = 1005;
char matrix[maxn][maxm];
vector<vector<pair<long long, long long>>> parent(
    maxn, vector<pair<long long, long long>>(maxm));
long long dfs_matrix[maxn][maxm];
long long n, m;
long long dfs(long long x, long long y, pair<long long, long long> parentn) {
  if (x < 0 || y < 0) return 0;
  if (x >= n || y >= m) return 0;
  if (matrix[x][y] == '*') return 0;
  if (dfs_matrix[x][y] != -1) return 0;
  dfs_matrix[x][y] = 0;
  parent[x][y] = parentn;
  long long ans = 1;
  ans += dfs(x + 1, y, parentn);
  ans += dfs(x - 1, y, parentn);
  ans += dfs(x, y + 1, parentn);
  ans += dfs(x, y - 1, parentn);
  dfs_matrix[x][y] = ans;
  return ans;
}
bool findPars(long long x, long long y) {
  if (x < 0 || y < 0) return 0;
  if (x >= n || y >= m) return 0;
  if (matrix[x][y] == '*') return 0;
  return true;
}
int main() {
  scanf("%lld", &n), scanf("%lld", &m);
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) dfs_matrix[i][j] = -1;
  for (int i = 0; i < n; i++) scanf("%s", matrix[i]);
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) dfs(i, j, make_pair(i, j));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (matrix[i][j] == '.')
        printf(".");
      else {
        set<pair<long long, long long>> pars;
        if (findPars(i - 1, j) == true)
          pars.insert(
              make_pair(parent[i - 1][j].first, parent[i - 1][j].second));
        if (findPars(i + 1, j) == true)
          pars.insert(
              make_pair(parent[i + 1][j].first, parent[i + 1][j].second));
        if (findPars(i, j - 1) == true)
          pars.insert(
              make_pair(parent[i][j - 1].first, parent[i][j - 1].second));
        if (findPars(i, j + 1) == true)
          pars.insert(
              make_pair(parent[i][j + 1].first, parent[i][j + 1].second));
        long long ans = 1;
        for (auto itr = pars.begin(); itr != pars.end(); itr++)
          ans += dfs_matrix[itr->first][itr->second];
        printf("%lld", ans % 10);
      }
    }
    printf("\n");
  }
}
