#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll h,w;
    ll temp = 0;
    cin >> h >> w;
    string s[h];
    rp(i,h) cin >> s[i];

    if(h == 1 && w==1){
      if(s[0][0] == '.') s[0][0] = '0';
    } else
    if(h == 1 && w > 1){
        rp(i,w){
          if(s[0][i] != '#'){
            //corner
            if(i == 0){
              temp = 0;
              if(s[0][1] == '#') temp++;
              s[0][0] = temp+48;continue;
            }
            if(i == w-1){
              temp = 0;
              if(s[0][w-2] == '#') temp++;
              s[0][w-1] = temp+48;continue;
            }
            temp = 0;
            if(s[0][i-1] == '#') temp++;
            if(s[0][i+1] == '#') temp++;
            s[0][i] = temp+48;
          }
        }
    }
    else if(h > 1 && w == 1){
      rp(i,h){
        if(s[i][0] != '#'){
          if(i == 0){
              temp=0;
              if(s[i+1][0] == '#') temp++;
              s[i][0] = temp+48;continue;
          }
          if(i == h-1){
            temp=0;
            if(s[i-1][0] == '#') temp++;
            s[i][0] = temp+48;continue;
          }
          temp = 0;
          if(s[i-1][0] == '#') temp++;
          if(s[i+1][0] == '#') temp++;
          s[i][0] = temp+48;
        }
      }
    }
    else if(h > 1 && w > 1){
      rp(i,h) rp(j,w){
      temp = 0;
      if(s[i][j] != '#'){
        //corner
        if(i == 0 && j == 0 )
        {
          temp = 0;
          if(s[i+1][j] == '#') temp++;
          if(s[i][j+1] == '#') temp++;
          if(s[i+1][j+1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
        if(i == 0 && j == w-1 )
        {
          temp = 0;
          if(s[i+1][j] == '#') temp++;
          if(s[i][j-1] == '#') temp++;
          if(s[i+1][j-1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
        if(i == h-1 && j == 0 )
        {
          temp = 0;
          if(s[i-1][j] == '#') temp++;
          if(s[i][j+1] == '#') temp++;
          if(s[i-1][j+1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
        if(i == h-1 && j == w-1)
        {
          temp = 0;
          if(s[i-1][j] == '#') temp++;
          if(s[i][j-1] == '#') temp++;
          if(s[i-1][j-1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }

        // sides
        if(i == 0 && j > 0 && j < w-1){
          temp = 0;
          if(s[i][j-1] == '#') temp++;
          if(s[i][j+1] == '#') temp++;
          if(s[i+1][j-1] == '#') temp++;
          if(s[i+1][j] == '#') temp++;
          if(s[i+1][j+1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
        if(i == h-1 && j > 0 && j < w-1){
          temp = 0;
          if(s[i][j-1] == '#') temp++;
          if(s[i][j+1] == '#') temp++;
          if(s[i-1][j-1] == '#') temp++;
          if(s[i-1][j] == '#') temp++;
          if(s[i-1][j+1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
        if(j == 0 && i > 0 && i < h-1){
          temp = 0;
          if(s[i+1][j] == '#') temp++;
          if(s[i-1][j] == '#') temp++;
          if(s[i][j+1] == '#') temp++;
          if(s[i-1][j+1] == '#') temp++;
          if(s[i+1][j+1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
        if(j == w-1 && i > 0 && i < h-1){
          temp = 0;
          if(s[i+1][j] == '#') temp++;
          if(s[i-1][j] == '#') temp++;
          if(s[i][j-1] == '#') temp++;
          if(s[i-1][j-1] == '#') temp++;
          if(s[i+1][j-1] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }

        // heart
        if(i > 0 && i < h-1 && j < w-1 && j > 0){
          temp = 0;
          if(s[i][j+1] == '#') temp++;
          if(s[i][j-1] == '#') temp++;
          if(s[i+1][j+1] == '#') temp++;
          if(s[i+1][j-1] == '#') temp++;
          if(s[i+1][j] == '#') temp++;
          if(s[i-1][j+1] == '#') temp++;
          if(s[i-1][j-1] == '#') temp++;
          if(s[i-1][j] == '#') temp++;
          s[i][j] = (char)(temp+48);
          continue;
        }
      }
    }
    }
    rp(i,h){
      cout << s[i] <<endl;
    }

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256