#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, i, j, m, n, s;
  string a[50][50];
  string b[50][50];
  cin >> x >> y;
  for (i = 1; i <= x; ++i) {
    for (j = 1; j <= y; ++j) {
      cin >> a[i][j];
    }
  }
  a[0][0] = "0";
  for (i = 1; i <= x; ++i) {
    a[i][0] = "0";
    a[0][i] = "0";
  }
  for (i = 1; i <= x; ++i) {
    for (j = 1; j <= y; ++j) {
      s = 0;
      if (a[i][j] == "#")
        b[i][j] = "#";
      else {
        for (m = -1; m < 2; ++m) {
          for (n = -1; n < 2; ++n) {
            if (a[i + m][j + n] == "#") ++s;
          }
        }
        switch (s) {
          case 1:
            b[i][j] = "1";
            break;
          case 2:
            b[i][j] = "2";
            break;
          case 3:
            b[i][j] = "3";
            break;
          case 4:
            b[i][j] = "4";
            break;
          case 5:
            b[i][j] = "5";
            break;
          case 6:
            b[i][j] = "6";
            break;
          case 7:
            b[i][j] = "7";
            break;
          case 8:
            b[i][j] = "8";
            break;
        }
      }
    }
  }
  for (i = 1; i <= x; ++i) {
    for (j = 1; j <= y; ++j) {
      cout << b[i][j];
      cout << " ";
    }
    cout << endl;
  }
  return 0;
}
