#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int H, W;
  string a = "#";
  cin >> H >> W;
  vector<vector<string>> mass(H, vector<string>(W, "#"));
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      char b;
      cin >> b;
      mass.at(i).at(j) = to_string(b);
    }
  }
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      int count = 0;
      if (mass.at(i).at(j) == a) {
        continue;
      } else if (i == 0 && j == 0) {
        if (mass.at(i).at(j + 1) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j + 1) == a) {
          count++;
        }
        mass.at(i).at(j) = to_string(count);
      } else if (i == H - 1 && j == 0) {
        if (mass.at(i - 1).at(j) == a) {
          count++;
        }
        if (mass.at(i - 1).at(j + 1) == a) {
          count++;
        }
        if (mass.at(i).at(j + 1) == a) {
          count++;
        }
        mass.at(i).at(j) = to_string(count);
      } else if (i == 0 && j == W - 1) {
        if (mass.at(i).at(j - 1) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j - 1) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j) == a) {
          count++;
        }
        mass.at(i).at(j) = to_string(count);
      } else if (i == H - 1 && j == W - 1) {
        if (mass.at(i - 1).at(j - 1) == a) {
          count++;
        }
        if (mass.at(i - 1).at(j) == a) {
          count++;
        }
        if (mass.at(i).at(j - 1) == a) {
          count++;
        }
        mass.at(i).at(j) = to_string(count);
      } else if (i == 0) {
        if (mass.at(i).at(j - 1) == a) {
          count++;
        }
        if (mass.at(i).at(j + 1) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j - 1) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j) == a) {
          count++;
        }
        if (mass.at(i + 1).at(j + 1) == a) {
          count++;
        }
        mass.at(i).at(j) = to_string(count);
      } else if (j == 0) {
        if (mass.at(i - 1).at(j) == a) count++;
        if (mass.at(i - 1).at(j + 1) == a) count++;
        if (mass.at(i).at(j + 1) == a) count++;
        if (mass.at(i + 1).at(j) == a) count++;
        if (mass.at(i + 1).at(j + 1) == a) count++;
        mass.at(i).at(j) = to_string(count);
      } else if (i == H - 1) {
        if (mass.at(i - 1).at(j - 1) == a) count++;
        if (mass.at(i - 1).at(j) == a) count++;
        if (mass.at(i - 1).at(j + 1) == a) count++;
        if (mass.at(i).at(j - 1) == a) count++;
        if (mass.at(i).at(j + 1) == a) count++;
        mass.at(i).at(j) = to_string(count);
      } else if (j == W - 1) {
        if (mass.at(i - 1).at(j - 1) == a) count++;
        if (mass.at(i - 1).at(j) == a) count++;
        if (mass.at(i).at(j - 1) == a) count++;
        if (mass.at(i + 1).at(j - 1) == a) count++;
        if (mass.at(i + 1).at(j) == a) count++;
        mass.at(i).at(j) = to_string(count);
      } else {
        if (mass.at(i - 1).at(j - 1) == a) count++;
        if (mass.at(i - 1).at(j) == a) count++;
        if (mass.at(i - 1).at(j + 1) == a) count++;
        if (mass.at(i).at(j - 1) == a) count++;
        if (mass.at(i).at(j + 1) == a) count++;
        if (mass.at(i + 1).at(j - 1) == a) count++;
        if (mass.at(i + 1).at(j) == a) count++;
        if (mass.at(i + 1).at(j + 1) == a) count++;
        mass.at(i).at(j) = to_string(count);
      }
    }
  }
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      cout << mass.at(i).at(j);
    }
    cout << endl;
  }
}
