#include <bits/stdc++.h>
using namespace std;
int number[1003][1003][2];
int n, m, sum;
int part = -1;
int parts[1000003];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
string s[1003];
bool isvalid(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) return 1;
  return 0;
}
int findsum(int x, int y) {
  int ans = 0;
  int anses[4];
  int point = 0;
  for (int i = 0; i < 4; i++) {
    if (isvalid(x + dx[i], y + dy[i]) && s[x + dx[i]][y + dy[i]] == '.') {
      bool flag = 0;
      int p = number[x + dx[i]][y + dy[i]][1];
      for (int j = 0; j < point; j++) {
        if (p == anses[j]) {
          flag = 1;
        }
      }
      if (flag == 0) {
        ans += parts[p];
      }
      anses[point] = p;
      point++;
    }
  }
  return ans + 1;
}
void dfs(int x, int y) {
  if (number[x][y][0] == 0) {
    sum++;
    number[x][y][0] = 1;
    number[x][y][1] = part;
    for (int i = 0; i < 4; i++) {
      if (isvalid(x + dx[i], y + dy[i])) {
        if (s[x + dx[i]][y + dy[i]] == '.') {
          dfs(x + dx[i], y + dy[i]);
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        if (number[i][j][0] == 0) {
          part++;
          dfs(i, j);
          parts[part] = sum;
          sum = 0;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '*') {
        s[i][j] = '0' + findsum(i, j) % 10;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s[i] << endl;
  }
}
