#全日本汚いコード選手権Pythonの部

H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(list(input()))
L = [[0 for w in range(W)] for h in range(H)]

if S[0][1]=="#":
  L[0][0]+=1
if S[1][0]=="#":
  L[0][0]+=1
if S[1][1]=="#":
  L[0][0]+=1
if S[W-1][1]=="#":
  L[W-1][0]+=1
if S[W-2][0]=="#":
  L[W-1][0]+=1
if S[W-2][1]=="#":
  L[W-1][0]+=1
if S[0][H-2]=="#":
  L[0][H-1]+=1
if S[1][H-1]=="#":
  L[0][H-1]+=1
if S[1][H-2]=="#":
  L[0][H-1]+=1
if S[W-1][H-2]=="#":
  L[W-1][H-1]+=1
if S[W-2][H-1]=="#":
  L[W-1][H-1]+=1
if S[W-2][H-2]=="#":
  L[W-1][H-1]+=1

for w in range(1,W-1):
  if S[0][w-1]=="#":
    L[0][w]+=1
  if S[0][w+1]=="#":
    L[0][w]+=1
  if S[1][w-1]=="#":
    L[0][w]+=1
  if S[1][w]=="#":
    L[0][w]+=1
  if S[1][w+1]=="#":
    L[0][w]+=1
  if S[H-1][w-1]=="#":
    L[H-1][w]+=1
  if S[H-1][w+1]=="#":
    L[H-1][w]+=1
  if S[H-2][w-1]=="#":
    L[H-1][w]+=1
  if S[H-2][w]=="#":
    L[H-1][w]+=1
  if S[H-2][w+1]=="#":
    L[H-1][w]+=1

for h in range(1,H-1):
  if S[h-1][0]=="#":
    L[h][0]+=1
  if S[h+1][0]=="#":
    L[h][0]+=1
  if S[h-1][1]=="#":
    L[h][0]+=1
  if S[h][1]=="#":
    L[h][0]+=1
  if S[h+1][1]=="#":
    L[h][0]+=1
  if S[h-1][W-1]=="#":
    L[h][W-1]+=1
  if S[h+1][W-1]=="#":
    L[h][W-1]+=1
  if S[h-1][W-2]=="#":
    L[h][W-1]+=1
  if S[h][W-2]=="#":
    L[h][W-1]+=1
  if S[h+1][W-2]=="#":
    L[h][W-1]+=1

for w in range(1,W-1):
  for h in range(1,H-1):
    if S[h-1][w-1]=="#":
      L[h][w]+=1
    if S[h-1][w]=="#":
      L[h][w]+=1
    if S[h-1][w+1]=="#":
      L[h][w]+=1
    if S[h][w-1]=="#":
      L[h][w]+=1
    if S[h][w+1]=="#":
      L[h][w]+=1
    if S[h+1][w-1]=="#":
      L[h][w]+=1
    if S[h+1][w]=="#":
      L[h][w]+=1
    if S[h+1][w+1]=="#":
      L[h][w]+=1

C = [["" for w in range(W)] for h in range(H)]

for w in range(W):
  for h in range(H):
    if S[h][w]==".":
      C[h][w]=str(L[h][w])
    else:
      C[h][w]="#"

o = ""
for c in C:
  o = ""
  for cc in c:
    o += cc
  print(o)

### FIXED CODE ###

#全日本汚いコード選手権Pythonの部
H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(list(input()))
L = [[0 for w in range(W)] for h in range(H)]

if H == 1 and W == 1:
  if S[0][0] == ".":
    L[0][0] = 0

elif H == 1:
  
  if S[0][1]=="#":
    L[0][0]+=1
  if S[0][W-2]=="#":
    L[0][W-1]+=1
  for w in range(1,W-1):
    if S[0][w-1]=="#":
      L[0][w]+=1
    if S[0][w+1]=="#":
      L[0][w]+=1

elif W == 1:
  
  if S[1][0]=="#":
    L[0][0]+=1
  if S[H-2][0]=="#":
    L[H-1][0]+=1
  for h in range(1,H-1):
    if S[h-1][0]=="#":
      L[h][0]+=1
    if S[h+1][0]=="#":
      L[h][0]+=1
  
  
else:

  if S[0][1]=="#":
    L[0][0]+=1
  if S[1][0]=="#":
    L[0][0]+=1
  if S[1][1]=="#":
    L[0][0]+=1
  if S[H-1][1]=="#":
    L[H-1][0]+=1
  if S[H-2][0]=="#":
    L[H-1][0]+=1
  if S[H-2][1]=="#":
    L[H-1][0]+=1
  if S[0][W-2]=="#":
    L[0][W-1]+=1
  if S[1][W-1]=="#":
    L[0][W-1]+=1
  if S[1][W-2]=="#":
    L[0][W-1]+=1
  if S[H-1][W-2]=="#":
    L[H-1][W-1]+=1
  if S[H-2][W-1]=="#":
    L[H-1][W-1]+=1
  if S[H-2][W-2]=="#":
    L[H-1][W-1]+=1

  for w in range(1,W-1):
    if S[0][w-1]=="#":
      L[0][w]+=1
    if S[0][w+1]=="#":
      L[0][w]+=1
    if S[1][w-1]=="#":
      L[0][w]+=1
    if S[1][w]=="#":
      L[0][w]+=1
    if S[1][w+1]=="#":
      L[0][w]+=1
    if S[H-1][w-1]=="#":
      L[H-1][w]+=1
    if S[H-1][w+1]=="#":
      L[H-1][w]+=1
    if S[H-2][w-1]=="#":
      L[H-1][w]+=1
    if S[H-2][w]=="#":
      L[H-1][w]+=1
    if S[H-2][w+1]=="#":
      L[H-1][w]+=1

  for h in range(1,H-1):
    if S[h-1][0]=="#":
      L[h][0]+=1
    if S[h+1][0]=="#":
      L[h][0]+=1
    if S[h-1][1]=="#":
      L[h][0]+=1
    if S[h][1]=="#":
      L[h][0]+=1
    if S[h+1][1]=="#":
      L[h][0]+=1
    if S[h-1][W-1]=="#":
      L[h][W-1]+=1
    if S[h+1][W-1]=="#":
      L[h][W-1]+=1
    if S[h-1][W-2]=="#":
      L[h][W-1]+=1
    if S[h][W-2]=="#":
      L[h][W-1]+=1
    if S[h+1][W-2]=="#":
      L[h][W-1]+=1

  for w in range(1,W-1):
    for h in range(1,H-1):
      if S[h-1][w-1]=="#":
        L[h][w]+=1
      if S[h-1][w]=="#":
        L[h][w]+=1
      if S[h-1][w+1]=="#":
        L[h][w]+=1
      if S[h][w-1]=="#":
        L[h][w]+=1
      if S[h][w+1]=="#":
        L[h][w]+=1
      if S[h+1][w-1]=="#":
        L[h][w]+=1
      if S[h+1][w]=="#":
        L[h][w]+=1
      if S[h+1][w+1]=="#":
        L[h][w]+=1

C = [["" for w in range(W)] for h in range(H)]

for w in range(W):
  for h in range(H):
    if S[h][w]==".":
      C[h][w]=str(L[h][w])
    else:
      C[h][w]="#"

o = ""
for c in C:
  o = ""
  for cc in c:
    o += cc
  print(o)