#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n, m;
vector<vector<char> > field;
vector<vector<int> > csize;
vector<vector<int> > zone_type;
bool check(int x, int y) { return !(x < 0 || x >= n || y < 0 || y >= m); }
int dfs(int x, int y) {
  if (!check(x, y) || !field[x][y]) {
    return 0;
  }
  if (csize[x][y] != -1) {
    return 0;
  }
  csize[x][y] = -2;
  int res = 1;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, -1, 0, 1};
  for (int i = 0; i < 4; ++i) {
    res += dfs(x + dx[i], y + dy[i]);
  }
  return res;
}
void dfs_set(int x, int y, int n, int t) {
  if (!check(x, y) || !field[x][y]) {
    return;
  }
  if (csize[x][y] != -2) {
    return;
  }
  csize[x][y] = n;
  zone_type[x][y] = t;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, -1, 0, 1};
  for (int i = 0; i < 4; ++i) {
    dfs_set(x + dx[i], y + dy[i], n, t);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  getchar();
  field.assign(n, vector<char>(m));
  csize.assign(n, vector<int>(m, -1));
  zone_type.assign(n, vector<int>(m, 0));
  int next_type = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c;
      scanf("%c", &c);
      field[i][j] = (c == '.');
    }
    getchar();
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (zone_type[i][j] == 0) dfs_set(i, j, dfs(i, j), ++next_type);
      if (csize[i][j] == -1) csize[i][j] = 0;
    }
  }
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < m; ++y) {
      if (!field[x][y]) {
        int res = 1;
        int dx[] = {-1, 0, 1, 0};
        int dy[] = {0, -1, 0, 1};
        int used_zones[4] = {};
        for (int i = 0; i < 4; ++i) {
          if (check(x + dx[i], y + dy[i])) {
            bool added = false;
            for (int j = 0; j < 4; ++j) {
              if (used_zones[j] == zone_type[x + dx[i]][y + dy[i]]) {
                added = true;
              }
            }
            if (!added) {
              used_zones[i] = zone_type[x + dx[i]][y + dy[i]];
              res += csize[x + dx[i]][y + dy[i]];
            }
          }
        }
        printf("%d", res % 10);
      } else {
        printf(".");
      }
    }
    printf("\n");
  }
  return 0;
}
