#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, cnt = 0;
  string s1, s2, s3;
  cin >> h >> w;
  for (int i = 0; i < (int)(h); i++) {
    if (i != 0 && i != h - 1) {
      s1 = s2;
      s2 = s3;
      cin >> s3;
      for (int j = 0; j < (int)(w); j++) {
        cnt = 0;
        if (j != 0 && j != w - 1) {
          for (int k = -1; k < 2; k++) {
            if (s1.at(j + k) == '#') cnt++;
            if (s2.at(j + k) == '#') cnt++;
            if (s3.at(j + k) == '#') cnt++;
          }
        } else if (j == 0) {
          if (s1.at(0) == '#') cnt++;
          if (w != 1 && s1.at(1) == '#') cnt++;
          if (s2.at(0) == '#') cnt++;
          if (w != 1 && s2.at(1) == '#') cnt++;
          if (s3.at(0) == '#') cnt++;
          if (w != 1 && s3.at(1) == '#') cnt++;
        } else {
          if (s1.at(w - 2) == '#') cnt++;
          if (s1.at(w - 1) == '#') cnt++;
          if (s2.at(w - 2) == '#') cnt++;
          if (s2.at(w - 1) == '#') cnt++;
          if (s3.at(w - 2) == '#') cnt++;
          if (s3.at(w - 1) == '#') cnt++;
        }
        if (s2.at(j) == '.')
          cout << cnt;
        else
          cout << '#';
      }
    } else if (i == 0) {
      if (w != 1) {
        cin >> s2 >> s3;
      } else {
        cin >> s2;
        s3 = "";
      }
      for (int j = 0; j < (int)(w); j++) {
        cnt = 0;
        if (j != 0 && j != w - 1) {
          for (int k = -1; k < 2; k++) {
            if (s2.at(j + k) == '#') cnt++;
            if (h != 1 && s3.at(j + k) == '#') cnt++;
          }
        } else if (j == 0) {
          if (w != 1 && s2.at(1) == '#') cnt++;
          if (h != 1 && s3.at(0) == '#') cnt++;
          if (w != 1 && s3.at(1) == '#') cnt++;
        } else {
          if (s2.at(w - 2) == '#') cnt++;
          if (h != 1 && s3.at(w - 2) == '#') cnt++;
          if (h != 1 && s3.at(w - 1) == '#') cnt++;
        }
        if (s2.at(j) == '.')
          cout << cnt;
        else
          cout << '#';
      }
    } else {
      s1 = s2;
      s2 = s3;
      s3 = "";
      for (int j = 0; j < (int)(w); j++) {
        cnt = 0;
        if (j != 0 && j != w - 1) {
          for (int k = -1; k < 2; k++) {
            if (s1.at(j + k) == '#') cnt++;
            if (s2.at(j + k) == '#') cnt++;
          }
        } else if (j == 0) {
          if (s1.at(0) == '#') cnt++;
          if (w != 1 && s1.at(1) == '#') cnt++;
          if (w != 1 && s2.at(1) == '#') cnt++;
        } else {
          if (s1.at(w - 2) == '#') cnt++;
          if (s1.at(w - 1) == '#') cnt++;
          if (s2.at(w - 2) == '#') cnt++;
        }
        if (s2.at(j) == '.')
          cout << cnt;
        else
          cout << '#';
      }
    }
    cout << endl;
  }
}
