#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> components = {0};
bool g[1100][1100];
int c[1100][1100];
bool visited[1100][1100];
int dfs(int x, int y, int cc) {
  if (visited[x][y] || !g[x][y] || x >= n || y >= m || x < 0 || y < 0) return 0;
  visited[x][y] = true;
  c[x][y] = cc;
  return 1 + dfs(x + 1, y, cc) + dfs(x - 1, y, cc) + dfs(x, y + 1, cc) +
         dfs(x, y - 1, cc);
}
int main() {
  memset(c, -1, sizeof c);
  memset(visited, 0, sizeof visited);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char c;
      scanf(" %c", &c);
      g[i][j] = (c == '.');
    }
  int comp = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      int res;
      if (res = dfs(i, j, comp)) {
        ++comp;
        components.push_back(res);
      } else if (c[i][j] == -1)
        c[i][j] = 0;
    }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j]) {
        putchar('.');
        continue;
      }
      set<int> taken;
      int cnt = 1;
      if (i > 0)
        if (taken.insert(c[i - 1][j]).second) cnt += components[c[i - 1][j]];
      if (j > 0)
        if (taken.insert(c[i][j - 1]).second) cnt += components[c[i][j - 1]];
      if (i < n - 1)
        if (taken.insert(c[i + 1][j]).second) cnt += components[c[i + 1][j]];
      if (j < m - 1)
        if (taken.insert(c[i][j + 1]).second) cnt += components[c[i][j + 1]];
      putchar(cnt % 10 + '0');
    }
    putchar('\n');
  }
  return 0;
}
