#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) cin >> S[i];
  int count = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i].at(j) == '.') {
        if (i >= 1 && i <= H - 2 && j >= 1 && j <= W - 2) {
          for (int k = -1; k <= 1; k++)
            for (int l = -1; l <= 1 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (i == 0 && j == 0) {
          for (int k = 0; k <= 1; k++)
            for (int l = 0; l <= 1 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (i == 0 && j == W - 1) {
          for (int k = 0; k <= 1; k++)
            for (int l = -1; l <= 0 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (i == 0) {
          for (int k = 0; k <= 1; k++)
            for (int l = -1; l <= 1 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (i == H - 1 && j == 0) {
          for (int k = -1; k <= 0; k++)
            for (int l = 0; l <= 1 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (i == H - 1 && j == W - 1) {
          for (int k = -1; k <= 0; k++)
            for (int l = -1; l <= 0 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (i == H - 1) {
          for (int k = -1; k <= 0; k++)
            for (int l = -1; l <= 1 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (j == 0) {
          for (int k = -1; k <= 1; k++)
            for (int l = 0; l <= 1 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        } else if (j == W - 1) {
          for (int k = -1; k <= 1; k++)
            for (int l = -1; l <= 0 && !(k == 0 && l == 0); l++) {
              if (S[i + k].at(j + l) == '#') count++;
            }
        }
        cout << count;
        count = 0;
      }
    }
  }
  return 0;
}
