#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1022;
char str[MAXN][MAXN];
vector<int> vec[MAXN * MAXN];
int smark[MAXN][MAXN];
int mark[MAXN * MAXN];
int ted[MAXN * MAXN];
int shm[MAXN * MAXN];
vector<int> mec;
void dfs(int v) {
  mec.push_back(v);
  mark[v] = 1;
  for (int i = 0; i < vec[v].size(); i++) {
    if (mark[vec[v][i]] == 0) {
      dfs(vec[v][i]);
    }
  }
}
int main() {
  int n, m, s = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> str[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      s++;
      smark[i][j] = s;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '.') {
        if (j < m - 1)
          if (str[i][j + 1] == '.') vec[smark[i][j]].push_back(smark[i][j + 1]);
        if (j > 0)
          if (str[i][j - 1] == '.') vec[smark[i][j]].push_back(smark[i][j - 1]);
        if (i > 0)
          if (str[i - 1][j] == '.') vec[smark[i][j]].push_back(smark[i - 1][j]);
        if (i < n - 1)
          if (str[i + 1][j] == '.') vec[smark[i][j]].push_back(smark[i + 1][j]);
      } else {
        mark[smark[i][j]] = 1;
      }
    }
  }
  int k = 0;
  for (int i = 1; i <= s; i++) {
    if (mark[i] != 1) {
      k++;
      mec.clear();
      dfs(i);
      for (int j = 0; j < mec.size(); j++) {
        ted[k] = mec.size();
        shm[mec[j]] = k;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '.') {
        cout << ".";
      } else {
        int jav = 0;
        set<int> see;
        see.clear();
        if (i > 0)
          if (str[i - 1][j] == '.') see.insert(shm[smark[i - 1][j]]);
        if (i < n - 1)
          if (str[i + 1][j] == '.') see.insert(shm[smark[i + 1][j]]);
        if (j < m - 1)
          if (str[i][j + 1] == '.') see.insert(shm[smark[i][j + 1]]);
        if (j > 0)
          if (str[i][j - 1] == '.') see.insert(shm[smark[i][j - 1]]);
        while (see.size()) {
          int x = *see.begin();
          see.erase(x);
          jav += ted[x];
        }
        jav++;
        cout << jav % 10;
      }
    }
    cout << endl;
  }
  return 0;
}
