h,w = map(int,input().split())
s = []

for i in range(h):
    a =list(input())
    s.append(a)

print(s)

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            c = 0
            if  i-1 >= 0 and i-1 <= h-1 and j-1 >= 0 and j-1 <= w-1:
               if s[i-1][j-1] == '#':
                 c += 1
            if  i >= 0 and i <= h-1 and j-1 >= 0 and j-1 <= w-1:
                if s[i][j-1] == '#':
                     c += 1
            if   i+11 >= 0 and i+1 <= h-1 and j-1 >= 0 and j-1 <= w-1:
                if s[i+1][j-1] == '#':
                    
                    c += 1
            if i-1 >= 0 and i-1 <= h-1 and j >= 0 and j <= w-1:
                if s[i-1][j] == '#' :
                    c += 1
            if   i >= 0 and i <= h-1 and j >= 0 and j <= w-1:
                if s[i][j] == '#':
                    c += 1
            if  i+1 >= 0 and i+1 <= h-1 and j >= 0 and j <= w-1:
                if s[i+1][j] == '#':
                    c += 1
            if i-1 >= 0 and i-1 <= h-1 and j+1 >= 0 and j+1 <= w-1:
                if s[i-1][j+1] == '#' :
                    c += 1
            if   i >= 0 and i <= h-1 and j+1 >= 0 and j+1 <= w-1:
                if s[i][j+1] == '#':
                    c += 1
            if  i+1 >= 0 and i+1 <= h-1 and j+1 >= 0 and j+1 <= w-1:
                if s[i+1][j+1] == '#':
                    c += 1
            s[i][j] = str(c)

for i in range(h):
    k = ''
    for j in range(w):
       
        k += s[i][j]
    print(k)