#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int cnt[1005][1005];
int tmp[1000000];
int num = 1;
int n, m;
int xx[] = {-1, 0, 0, 1};
int yy[] = {0, -1, 1, 0};
void dfs(int x, int y) {
  cnt[x][y] = num;
  tmp[num]++;
  for (int i = 0; i < 4; i++) {
    if (a[x + xx[i]][y + yy[i]] && !cnt[x + xx[i]][y + yy[i]])
      dfs(x + xx[i], y + yy[i]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        a[i][j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] && !cnt[i][j]) {
        dfs(i, j);
        num++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!a[i][j]) {
        vector<int> v;
        int ans = 1;
        for (int k = 0; k < 4; k++) {
          if (a[i + xx[k]][j + yy[k]]) {
            int r = 0;
            for (r = 0; r < v.size(); r++) {
              if (cnt[i + xx[k]][j + yy[k]] == v[r]) {
                break;
              }
            }
            if (r < v.size())
              ;
            else {
              v.push_back(cnt[i + xx[k]][j + yy[k]]);
              ans += tmp[cnt[i + xx[k]][j + yy[k]]];
            }
          }
        }
        cout << ans % 10;
      } else {
        cout << '.';
      }
    }
    cout << "\n";
  }
}
