#include <bits/stdc++.h>
using namespace std;
int n;
int m;
char g[1005][1005];
int a[1005][1005];
char ans[1005][1005];
int x[] = {0, 0, 1, -1};
int y[] = {1, -1, 0, 0};
bool visited[1005][1005];
int num = 0;
int cur = 0;
int com[1005][1005];
void dfs(int i, int j) {
  num++;
  visited[i][j] = 1;
  for (int k = 0; k < 4; k++) {
    int xx = i + x[k];
    int yy = j + y[k];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m && !visited[xx][yy] &&
        g[xx][yy] == '.')
      dfs(xx, yy);
  }
}
bool used[1005][1005];
void DFS(int i, int j) {
  com[i][j] = cur;
  a[i][j] = num;
  used[i][j] = 1;
  for (int k = 0; k < 4; k++) {
    int xx = i + x[k];
    int yy = j + y[k];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m && !used[xx][yy] &&
        g[xx][yy] == '.')
      DFS(xx, yy);
  }
}
set<int> s;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", &g[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '.') {
        num = 0;
        if (!visited[i][j]) {
          dfs(i, j);
          cur++;
          DFS(i, j);
        }
      }
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '.')
        ans[i][j] = '.';
      else {
        s.clear();
        int c = 0;
        for (int k = 0; k < 4; k++) {
          int xx = i + x[k];
          int yy = j + y[k];
          if (xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] == '.' &&
              s.find(com[xx][yy]) == s.end()) {
            c += a[xx][yy];
            s.insert(com[xx][yy]);
          }
        }
        ans[i][j] = '0' + ((c + 1) % 10);
      }
    }
  for (int i = 0; i < n; i++) printf("%s\n", ans[i]);
  return 0;
}
