#include <bits/stdc++.h>
using namespace std;
char g[1005][1005];
int visited[1005][1005];
int mark[1005 * 1005];
int v[1005 * 1005];
int k = 1;
int n, m;
int dir[2][4] = {{0, 0, -1, 1}, {-1, 1, 0, 0}};
struct pos {
  int x, y;
};
queue<pos> q;
bool islegal(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m)
    return true;
  else
    return false;
}
void dfs(int x, int y, int &count) {
  visited[x][y] = k;
  pos r = {x, y};
  q.push(r);
  count++;
  for (int i = 0; i < 4; i++) {
    int dx = x + dir[0][i];
    int dy = y + dir[1][i];
    if (islegal(dx, dy) && g[dx][dy] == '.' && !visited[dx][dy]) {
      dfs(dx, dy, count);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '.' && !visited[i][j]) {
        int count = 0;
        dfs(i, j, count);
        mark[k++] = count;
      }
    }
  }
  int t = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '*') {
        int ans = 0;
        for (int a = 0; a < 4; a++) {
          int dx = i + dir[0][a];
          int dy = j + dir[1][a];
          if (islegal(dx, dy) && g[dx][dy] == '.' && v[visited[dx][dy]] < t) {
            ans += mark[visited[dx][dy]];
            v[visited[dx][dy]] = t;
          }
        }
        cout << (ans + 1) % 10;
      } else
        cout << g[i][j];
      t++;
    }
    cout << endl;
  }
  return 0;
}
