#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n);++i)
using namespace std;
typedef long long ll;

int main(){
    int H, W;
    cin >> H >> W;
    char S[50][50];
    char ans[50][50];
    int baku[50][50];
    rep(i, H){
        rep(j,W){
            cin >> S[i][j];
            baku[i][j] = 0;
        }
    }

    rep(i, H){
        rep(j,W){
            if (S[i][j] == '#'){
                ans[i][j] = '#';
                cout << ans[i][j];
                if (j != 0 && j == W-1) cout << endl;
                continue;
            }
            rep(k, 3)
            {
                rep(l,3){
                    if (S[k + i - 1][l + j - 1] == '#') baku[i][j]++;
                }
            }
          ans[i][j] = '0' + baku[i][j];
          cout << ans[i][j];
          if (j != 0 && j == W-1) cout << endl;
        }
    }
}
