#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " |       ";
  __f(comma + 1, args...);
}
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(15);
}
long long modpow(long long a, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    p /= 2;
  }
  return ret % mod;
}
long long power(long long a, long long p) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = (ret * a);
    a = (a * a);
    p /= 2;
  }
  return ret;
}
const int MAX = 1000010;
class Union_Find {
 public:
  int id[MAX], sz[MAX];
  Union_Find(int n) {
    for (int i = 0; i < n; i++) {
      id[i] = i;
      sz[i] = 1;
    }
  }
  int root(int i) {
    while (i != id[i]) {
      id[i] = id[id[i]];
      i = id[i];
    }
    return i;
  }
  int find(int p, int q) { return root(p) == root(q); }
  void join(int p, int q) {
    int i = root(p);
    int j = root(q);
    if (sz[i] < sz[j]) {
      id[i] = j;
      sz[j] += sz[i];
    } else {
      id[j] = i;
      sz[i] += sz[j];
    }
  }
};
string s[1010];
int n, m;
Union_Find uf(1000010);
bool vis[1010][1010];
bool check(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) return 1;
  return 0;
}
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++)
    if (check(x + dx[i], y + dy[i]) && !vis[x + dx[i]][y + dy[i]] &&
        s[x + dx[i]][y + dy[i]] == '.') {
      uf.join(m * x + y, m * (x + dx[i]) + y + dy[i]);
      dfs(x + dx[i], y + dy[i]);
    }
}
string ans[1010];
int main() {
  FastIO();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    ans[i].resize(m);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '.' && !vis[i][j]) dfs(i, j);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        ans[i][j] = '.';
        continue;
      }
      long long tmp = 0;
      set<int> st;
      for (int k = 0; k < 4; k++)
        if (check(i + dx[k], j + dy[k]) && s[i + dx[k]][j + dy[k]] == '.')
          st.insert(uf.root(m * (i + dx[k]) + j + dy[k]));
      for (auto& it : st) tmp += uf.sz[it];
      tmp++;
      tmp %= 10;
      ans[i][j] = (char)(tmp + '0');
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << ans[i][j];
    cout << '\n';
  }
  return 0;
}
