#include <bits/stdc++.h>
using namespace std;
char grid[1001][1001];
int visited[1001][1001];
int componentIDs[1001][1001];
int dfs(int p, int q, int componentID, int val) {
  int res = 1;
  visited[p][q] = -1;
  for (int i = -1; i <= 1; ++i) {
    for (int j = -1; j <= 1; ++j) {
      if (abs(i) + abs(j) == 1 && grid[p + i][q + j] == '.' &&
          visited[p + i][q + j] == (componentID ? -2 : 0)) {
        res += dfs(p + i, q + j, componentID, val);
      }
    }
  }
  if (componentID) {
    visited[p][q] = val;
    componentIDs[p][q] = componentID;
  } else
    visited[p][q] = -2;
  return res;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", grid[i]);
  int componentID = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == '.' && visited[i][j] == 0) {
        int res = dfs(i, j, 0, 0);
        dfs(i, j, componentID, res);
        componentID += 1;
      }
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == '*') {
        int res = 1, k = 0;
        int seenIDs[4];
        for (int p = -1; p <= 1; ++p) {
          for (int q = -1; q <= 1; ++q) {
            if (abs(p) + abs(q) == 1 && grid[p + i][q + j] == '.') {
              bool seen = false;
              for (int t = 0; t < k; ++t) {
                seen = seen || (componentIDs[i + p][j + q] == seenIDs[t]);
              }
              if (!seen) {
                res += visited[i + p][j + q];
                seenIDs[k++] = componentIDs[i + p][j + q];
              }
            }
          }
        }
        grid[i][j] = '0' + (res % 10);
      }
    }
  for (int i = 0; i < n; ++i) printf("%s\n", grid[i]);
  return 0;
}
