#include <bits/stdc++.h>
using namespace std;
int n, m;
bool inbound(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m) return true;
  return false;
}
char inttochar(int a) { return a + '0'; }
int main() {
  int xd[4] = {1, 0, 0, -1};
  int yd[4] = {0, 1, -1, 0};
  scanf("%d %d", &n, &m);
  char in[n][m];
  int visited[n][m], comp[n][m];
  memset(visited, 0, sizeof(visited));
  memset(comp, 0, sizeof(comp));
  int ans[n][m];
  for (int i = 0; i < n; i++) {
    scanf("%s", in[i]);
  }
  int comp_counter = 1;
  const int xcord = 3, ycord = 3;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (in[i][j] == '*') ans[i][j] = -1;
      if (in[i][j] == '.' && !visited[i][j]) {
        visited[i][j] = 1;
        list<pair<int, int> > queue, storer;
        queue.push_back(pair<int, int>(i, j));
        int count = 1;
        ans[i][j] = 0;
        comp[i][j] = comp_counter;
        while (!queue.empty()) {
          pair<int, int> s = queue.front();
          queue.pop_front();
          int x = s.first, y = s.second;
          for (int k = 0; k <= 3; k++) {
            if (inbound(x + xd[k], y + yd[k])) {
              if (!visited[x + xd[k]][y + yd[k]] &&
                  in[x + xd[k]][y + yd[k]] == '.') {
                visited[x + xd[k]][y + yd[k]] = 1;
                queue.push_back(pair<int, int>(x + xd[k], y + yd[k]));
                storer.push_back(pair<int, int>(x + xd[k], y + yd[k]));
                count++;
              }
            }
          }
        }
        ans[i][j] = count;
        while (!storer.empty()) {
          pair<int, int> s = storer.front();
          storer.pop_front();
          int x = s.first, y = s.second;
          ans[x][y] = ans[i][j];
          comp[x][y] = comp_counter;
        }
        comp_counter++;
      }
    }
  }
  char out[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (in[i][j] == '*') {
        int temp = 1;
        vector<int> compos;
        for (int k = 0; k < 4; k++) {
          if (inbound(i + xd[k], j + yd[k])) {
            if (in[i + xd[k]][j + yd[k]] == '.') {
              if (compos.size() == 0) {
                compos.push_back(comp[i + xd[k]][j + yd[k]]);
                temp += ans[i + xd[k]][j + yd[k]];
                continue;
              }
              auto it = find(compos.begin(), compos.end(),
                             comp[i + xd[k]][j + yd[k]]);
              if (it == compos.end()) {
                compos.push_back(comp[i + xd[k]][j + yd[k]]);
                temp += ans[i + xd[k]][j + yd[k]];
              }
            }
          }
        }
        temp %= 10;
        out[i][j] = inttochar(temp);
      } else
        out[i][j] = '.';
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%c", out[i][j]);
    }
    printf("\n");
  }
}
