#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> mine(H);
  for (int i = 0; i < H; i++) {
    cin >> mine.at(i);
    for (int j = 0; j < W; j++) {
      if (mine.at(i).at(j) == '.') {
        mine.at(i).at(j) = '0';
      }
    }
  }
  for (int l = 0; l < H; l++) {
    for (int m = 0; m < W; m++) {
      if (mine.at(l).at(m) == '#') {
        if (l != 0 && l != H - 1) {
          if (m != 0 && m != W - 1) {
            for (int n = 0; n < 3; n++) {
              for (int o = 0; o < 3; o++) {
                if (mine.at(l - o + 1).at(m - n + 1) != '#') {
                  mine.at(l - o + 1).at(m - n + 1) += 1;
                }
              }
            }
          } else if (m == 0) {
            for (int p = 0; p < 2; p++) {
              for (int q = 0; q < 3; q++) {
                if (mine.at(l - q + 1).at(1 - p) != '#') {
                  mine.at(l - q + 1).at(1 - p) += 1;
                }
              }
            }
          } else if (m == W - 1) {
            for (int r = 0; r < 2; r++) {
              for (int s = 0; s < 3; s++) {
                if (mine.at(l - s + 1).at(W - r - 1) != '#') {
                  mine.at(l - s + 1).at(W - r - 1) += 1;
                }
              }
            }
          }
        } else if (l == 0) {
          if (m != 0 && m != W - 1) {
            for (int t = 0; t < 3; t++) {
              for (int u = 0; u < 2; u++) {
                if (mine.at(1 - u).at(m - t + 1) != '#') {
                  mine.at(1 - u).at(m - t + 1) += 1;
                }
              }
            }
          } else if (m == 0) {
            for (int v = 0; v < 2; v++) {
              for (int w = 0; w < 2; w++) {
                if (mine.at(1 - w).at(1 - v) != '#') {
                  mine.at(1 - w).at(1 - v) += 1;
                }
              }
            }
          } else if (m == W - 1) {
            for (int x = 0; x < 2; x++) {
              for (int y = 0; y < 2; y++) {
                if (mine.at(1 - y).at(W - x - 1) != '#') {
                  mine.at(1 - y).at(W - x - 1) += 1;
                }
              }
            }
          } else if (l == H - 1) {
            if (m != 0 && m != W - 1) {
              for (int z = 0; z < 3; z++) {
                for (int a = 0; a < 2; a++) {
                  if (mine.at(H - a - 1).at(m - z + 1) != '#') {
                    mine.at(H - a - 1).at(m - z + 1) += 1;
                  }
                }
              }
            } else if (m == 0) {
              for (int b = 0; b < 2; b++) {
                for (int c = 0; c < 2; c++) {
                  if (mine.at(H - c - 1).at(1 - b) != '#') {
                    mine.at(H - c - 1).at(1 - b) += 1;
                  }
                }
              }
            } else if (m == W - 1) {
              for (int d = 0; d < 2; d++) {
                for (int e = 0; e < 2; e++) {
                  if (mine.at(H - e - 1).at(W - d - 1) != '#') {
                    mine.at(H - e - 1).at(W - d - 1) += 1;
                  }
                }
              }
            }
          }
        }
      }
    }
    for (int k = 0; k < H; k++) {
      cout << mine.at(k) << endl;
    }
  }
}
