#include <bits/stdc++.h>
using namespace std;
int x = 99;
int n, m, siz;
int a[1005][1005];
bool vis[1005][1005];
bool is[1005][1005];
map<pair<int, int>, int> mp;
string s[1005];
int hisab(int row, int col) {
  map<int, int> mr;
  int ans = 1;
  if (row != 0 && mr[mp[make_pair(row - 1, col)]] == false) {
    ans += a[row - 1][col];
    mr[mp[make_pair(row - 1, col)]] = true;
  }
  if (col != 0 && mr[mp[make_pair(row, col - 1)]] == false) {
    mr[mp[make_pair(row, col - 1)]] = true;
    ans += a[row][col - 1];
  }
  if (row != (n - 1) && mr[mp[make_pair(row + 1, col)]] == false) {
    mr[mp[make_pair(row + 1, col)]] = true;
    ans += a[row + 1][col];
  }
  if (col != (m - 1) && mr[mp[make_pair(row, col + 1)]] == false) {
    mr[mp[make_pair(row, col + 1)]] = true;
    ans += a[row][col + 1];
  }
  return ans % 10;
}
void dfs(int row, int col) {
  if (row < 0 || col < 0) return;
  if (row >= n || col >= m) return;
  if (vis[row][col]) return;
  vis[row][col] = true;
  siz++;
  mp[make_pair(row, col)] = x;
  if ((row - 1) >= 0 && s[row - 1][col] == '.') dfs(row - 1, col);
  if ((col - 1) >= 0 && s[row][col - 1] == '.') dfs(row, col - 1);
  if ((row + 1) < n && s[row + 1][col] == '.') dfs(row + 1, col);
  if ((col + 1) < m && s[row][col + 1] == '.') dfs(row, col + 1);
}
void bfs(int row, int col) {
  if (row < 0 || col < 0) return;
  if (row >= n || col >= m) return;
  if (is[row][col]) return;
  is[row][col] = true;
  if ((row - 1) >= 0 && s[row - 1][col] == '.') bfs(row - 1, col);
  if ((col - 1) >= 0 && s[row][col - 1] == '.') bfs(row, col - 1);
  if ((row + 1) < n && s[row + 1][col] == '.') bfs(row + 1, col);
  if ((col + 1) < m && s[row][col + 1] == '.') bfs(row, col + 1);
  a[row][col] = siz;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(a, 0, sizeof a);
  memset(vis, false, sizeof vis);
  memset(is, false, sizeof is);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '.' && vis[i][j] == false) {
        siz = 0;
        x++;
        dfs(i, j);
        bfs(i, j);
      }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (s[i][j] == '*')
        cout << hisab(i, j);
      else
        cout << '.';
    cout << endl;
  }
}
