#include <bits/stdc++.h>
using namespace std;
int b[1010][1010], fa[1010][1010], c, d, e, f, g, h[5];
int find(int q, int w) {
  if (fa[q][w] == q * d + w - 1) return q * d + w - 1;
  fa[q][w] = find(fa[q][w] / d, fa[q][w] % d + 1);
  return fa[q][w];
}
int main() {
  char a[1010][1010];
  cin >> c >> d;
  for (int m = 1; m <= c; m++)
    for (int n = 1; n <= d; n++) {
      fa[m][n] = m * d + n - 1;
      b[m][n] = 1;
    }
  for (int m = 1; m <= c; m++)
    for (int n = 1; n <= d; n++) {
      scanf("%c", &a[m][n]);
      while (a[m][n] != '.' && a[m][n] != '*') scanf("%c", &a[m][n]);
      if (a[m][n] == '.') {
        if (n - 1 > 0 && a[m][n - 1] == '.') {
          fa[m][n] = find(m, n - 1);
          b[find(m, n - 1) / d][find(m, n - 1) % d + 1] += b[m][n];
          ;
        }
        if (m - 1 > 0 && a[m - 1][n] == '.' && find(m - 1, n) != find(m, n)) {
          b[find(m - 1, n) / d][find(m - 1, n) % d + 1] +=
              b[find(m, n) / d][find(m, n) % d + 1];
          fa[find(m, n) / d][find(m, n) % d + 1] = find(m - 1, n);
        }
      }
    }
  for (int m = 1; m <= c; m++) {
    for (int n = 1; n <= d; n++)
      if (a[m][n] == '.')
        printf(".");
      else {
        g = 1;
        f = 0;
        int o = 1;
        if (m - 1 > 0 && a[m - 1][n] == '.') {
          for (int v = 1; v <= f; v++)
            if (h[v] == find(m - 1, n)) o = 0;
          if (o) h[++f] = find(m - 1, n);
        }
        o = 1;
        if (n - 1 > 0 && a[m][n - 1] == '.') {
          for (int v = 1; v <= f; v++)
            if (h[v] == find(m, n - 1)) o = 0;
          if (o) h[++f] = find(m, n - 1);
        }
        o = 1;
        if (m + 1 <= c && a[m + 1][n] == '.') {
          for (int v = 1; v <= f; v++)
            if (h[v] == find(m + 1, n)) o = 0;
          if (o) h[++f] = find(m + 1, n);
        }
        o = 1;
        if (n + 1 <= d && a[m][n + 1] == '.') {
          for (int v = 1; v <= f; v++)
            if (h[v] == find(m, n + 1)) o = 0;
          if (o) h[++f] = find(m, n + 1);
        }
        for (int v = 1; v <= f; v++) g += b[h[v] / d][h[v] % d + 1];
        cout << g % 10;
      }
    cout << endl;
  }
}
