#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
int vis[maxn][maxn];
char mp[maxn][maxn];
int n, m;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct Node {
  int x, y;
};
queue<Node> Q;
map<int, int> M;
set<int> S;
set<int>::iterator it;
bool check(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m) return false;
  if (vis[x][y]) return false;
  if (mp[x][y] != '.') return false;
  return true;
}
void BFS(int x1, int y1, int cnt) {
  vis[x1][y1] = cnt;
  int ans = 0;
  Q.push((Node){x1, y1});
  while (!Q.empty()) {
    ans++;
    Node &u = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int x = u.x + dx[i];
      int y = u.y + dy[i];
      if (check(x, y)) {
        vis[x][y] = cnt;
        Q.push(Node{x, y});
      }
    }
  }
  M[cnt] = ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  memset(vis, 0, sizeof(vis));
  int cnt = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mp[i][j] == '.' && vis[i][j] == 0) {
        BFS(i, j, cnt++);
      }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (mp[i][j] == '*') {
        S.clear();
        if (i > 0) S.insert(vis[i - 1][j]);
        if (i < n - 1) S.insert(vis[i + 1][j]);
        if (j > 0) S.insert(vis[i][j - 1]);
        if (j < m - 1) S.insert(vis[i][j + 1]);
        int res = 1;
        for (it = S.begin(); it != S.end(); it++) res += M[*it];
        mp[i][j] = char('0' + res % 10);
      }
    }
  for (int i = 0; i < n; i++) {
    printf("%s\n", mp[i]);
  }
  return 0;
}
