//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int h,w;
    cin >> h >> w;
    char map[h][w];

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin >> map[i][j];
        }
    }
    
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            int count = 0;
            if(map[i][j]=='#')
            {
                cout << map[i][j];
                continue;
            }
            else if(i==0 && j==0)
            {
                if(map[i][j+1]=='#') count += 1;
                if(map[i+1][j]=='#') count += 1;
                if(map[i+1][j+1]=='#') count += 1;
            }
            else if(i==0 && j==w-1)
            {
                if(map[i][j-1]=='#') count += 1;
                if(map[i+1][j]=='#') count += 1;
                if(map[i+1][j-1]=='#') count += 1;
            }
            else if(j==0 && i==h-1)
            {
                if(map[i-1][j]=='#') count += 1;
                if(map[i][j+1]=='#') count += 1;
                if(map[i-1][j+1]=='#') count += 1;                
            }
            else if(i==h-1 && j==w-1)
            {
                if(map[i][j-1]=='#') count += 1;
                if(map[i-1][j]=='#') count += 1;
                if(map[i-1][j-1]=='#') count += 1;                
            }
            else if(i==0)
            {
                if(map[i][j-1]=='#') count += 1;
                if(map[i+1][j-1]=='#') count += 1;
                if(map[i+1][j]=='#') count += 1;
                if(map[i+1][j+1]=='#') count += 1;
                if(map[i][j+1]=='#') count += 1;                
            }
            else if(j==0)
            {
                if(map[i-1][j]=='#') count += 1;
                if(map[i-1][j+1]=='#') count += 1;
                if(map[i][j+1]=='#') count += 1;
                if(map[i+1][j+1]=='#') count += 1;
                if(map[i+1][j]=='#') count += 1;                
            }
            else if(i==h-1)
            {
                if(map[i][j-1]=='#') count += 1;
                if(map[i-1][j-1]=='#') count += 1;
                if(map[i-1][j]=='#') count += 1;
                if(map[i-1][j+1]=='#') count += 1;
                if(map[i][j+1]=='#') count += 1;                
            }
            else if(j==w-1)
            {
                if(map[i-1][j]=='#') count += 1;
                if(map[i-1][j-1]=='#') count += 1;
                if(map[i][j-1]=='#') count += 1;
                if(map[i+1][j-1]=='#') count += 1;
                if(map[i+1][j]=='#') count += 1;                
            }
            else
            {
                if(map[i-1][j-1]=='#') count += 1;
                if(map[i-1][j]=='#') count += 1;
                if(map[i-1][j+1]=='#') count += 1;
                if(map[i][j-1]=='#') count += 1;
                if(map[i][j+1]=='#') count += 1;               
                if(map[i+1][j-1]=='#') count += 1;       
                if(map[i+1][j]=='#') count += 1;  
                if(map[i+1][j+1]=='#') count += 1;                   
            }

            cout << count;
        }
        cout << endl;
    }
    return 0;
}