#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,s,n) for (int i = s; i < n; ++i)
#define drep(i,s,n) for (int i = n; i >= s; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void printvv(vector<vector<auto>> vv, int n)
{
  cout << '[' << endl;
  rep(q, 0, n)
  {
    cout << '[';
    rep(p, 0, n)
    {
      cout << vv.at(q).at(p) << ',';
    }
    cout << ']' << endl;
  }
  cout << ']' << endl;
}

void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

//------------------------------------------------------------
int check(char c)
{
  if (c=='#') return 1;
  else        return 0;
}

void solve() {
  int h,w,sum=0;
  cin >> h >> w;

  vector<string> v(h);
  rep(i,0,h) cin >> v.at(i);

  vector<string> ans(h, string(w,'#'));

  rep(i,0,h)
  {
    rep(j,0,w)
    {
      if (v.at(i).at(j)!='#')
      {
        sum=0;
        if (i==0 && i==h-1)
        {
          if(j==0 && j==w-1) sum=0;
          else if (j==0) sum+=check(v.at(0).at(1));
          else if (j==w-1) sum+=check(v.at(0).at(w-2));
          else
          {
            sum+=check(v.at(0).at(j-1));
            sum+=check(v.at(0).at(j+1));
          }
        }
        else if (i==0)
        {
          if (j==0 && j==w-1) sum+=check(v.at(1).at(0));
          else if (j==0)
          {
            sum+=check(v.at(0).at(1));
            sum+=check(v.at(1).at(0));
            sum+=check(v.at(1).at(1));
          }
          else if(j==w-1)
          {
            sum+=check(v.at(0).at(w-2));
            sum+=check(v.at(1).at(w-2));
            sum+=check(v.at(1).at(w-1));
          }
          else
          {
            sum+=check(v.at(0).at(j-1));
            sum+=check(v.at(0).at(j+1));
            rep(k,j-1,j+2) sum+=check(v.at(1).at(k));
          }
        }
        else if (i==h-1)
        {
          if (j==0 && j==w-1) sum+=check(v.at(h-2).at(0));
          else if (j==0)
          {
            sum+=check(v.at(h-1).at(1));
            sum+=check(v.at(h-2).at(0));
            sum+=check(v.at(h-2).at(1));
          }
          else if(j==w-1)
          {
            sum+=check(v.at(h-1).at(w-2));
            sum+=check(v.at(h-2).at(w-2));
            sum+=check(v.at(h-2).at(w-1));
          }
          else
          {
            sum+=check(v.at(h-1).at(j-1));
            sum+=check(v.at(h-1).at(j+1));
            rep(k,j-1,j+2) sum+=check(v.at(h-2).at(k));
          }
        }
        else if (j==0 && j==w-1)
        {
          sum+=check(v.at(i-1).at(j));
          sum+=check(v.at(i+1).at(j));
        }
        else if (j==0) // i!=0 && i!=h-1
        {
          sum+=check(v.at(i-1).at(j));
          sum+=check(v.at(i-1).at(j+1));
          sum+=check(v.at(i).at(j+1));
          sum+=check(v.at(i+1).at(j));
          sum+=check(v.at(i+1).at(j+1));
        }
        else if (j==w-1)
        {
          sum+=check(v.at(i-1).at(w-2));
          sum+=check(v.at(i-1).at(w-1));
          sum+=check(v.at(i).at(w-2));
          sum+=check(v.at(i+1).at(w-2));
          sum+=check(v.at(i+1).at(w-1));
        }
        else
        {
          rep(k,j-1,j+2) sum+=check(v.at(i-1).at(k));
          rep(k,j-1,j+2) sum+=check(v.at(i+1).at(k));
          sum+=check(v.at(i).at(j-1));
          sum+=check(v.at(i).at(j+1));
        }

        ans.at(i).at(j) = '0'+sum;
      }
    }
  }

  rep(q, 0, h)
  {
    rep(p, 0, w)
    {
      cout << ans.at(q).at(p);
    }
    cout << endl;
  }

  return;
}


Measured memory_bytes: 256