#include <bits/stdc++.h>
using namespace std;
int movi[] = {-1, 1, 0, 0};
int movj[] = {0, 0, -1, 1};
int n, m;
char input[2000][2000];
int v[2000][2000];
int idcom[2000][2000];
int ncom = 0;
int tamcom[2000000];
void calcula(int i, int j, int id) {
  if (v[i][j] != 1) return;
  v[i][j] = 2;
  idcom[i][j] = id;
  tamcom[id]++;
  for (int k = 0; k < 4; k++) calcula(i + movi[k], j + movj[k], id);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", input[i]);
    for (int j = 0; j < m; j++) v[i][j + 1] = input[i][j] == '.';
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (v[i][j] == 1) {
        calcula(i, j, ncom);
        ncom++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (v[i][j] == 0) {
        set<int> s;
        for (int k = 0; k < 4; k++) {
          int nexti = i + movi[k];
          int nextj = j + movj[k];
          if (v[nexti][nextj] != 0) s.insert(idcom[nexti][nextj]);
        }
        int sol = 1;
        for (set<int>::iterator it = s.begin(); it != s.end(); it++)
          sol += tamcom[*it];
        input[i][j - 1] = char('0' + sol % 10);
      }
    }
  }
  for (int i = 1; i <= n; i++) puts(input[i]);
}
