#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define P 1000000007
#define inf 1e18
int main()
{
    ll i, n, j, m;
    cin >> n >> m;
    char s[n + 5][m + 5];

    for (i = 0; i < n + 3; i++)
    {
        for (j = 0; j < n + 3; j++)
        {
            s[i][j] = '?';
        }
    }
    for (i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= m; j++)
        {
            cin >> s[i][j];
        }
    }

    ll count[n + 4][m + 4] = {0};

    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            if (s[i][j] == '.')
            {
                if (s[i - 1][j] == '#')
                {
                    count[i][j]++;
                }
                if (s[i + 1][j] == '#')
                {
                    count[i][j]++;
                }
                if (s[i][j + 1] == '#')
                {
                    count[i][j]++;
                }
                if (s[i][j - 1] == '#')
                {
                    count[i][j]++;
                }
                if (s[i - 1][j - 1] == '#')
                {
                    count[i][j]++;
                }
                if (s[i - 1][j + 1] == '#')
                {
                    count[i][j]++;
                }
                if (s[i + 1][j - 1] == '#')
                {
                    count[i][j]++;
                }
                if (s[i + 1][j + 1] == '#')
                {
                    count[i][j]++;
                }
                if (s[i][j] == '#')
                {
                    count[i][j]++;
                }
            }
        }
    }

    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        { 
            if(s[i][j] == '#')
             { 
                 cout<<s[i][j];
             }
             else 
             { 
                 cout<<count[i][j];
             }
        } 
        cout<<"\n";
    }

    return (0);
}