h, w = map(int, input().split())
s = [0] * h
for i in range(h):
    s[i] = str(input())
t = [[0]*w]*h
for j in range(h):
    if j == 0:
        for k in range(w):
            if k == 0:
                u = s[0][1] + s[1][0] + s[1][1]
            elif k == w-1:
                u = s[0][k-1] +s[1][k-1] + s[1][k]
            else:
                u = s[0][k-1] +s[0][k+1] + s[1][k-1] + s[1][k] + s[1][k+1]
            v = u.count('#')
            if s[j][k] == '#':
                v = '#'
            t[j][k] = str(v)
    elif j == h-1:
        for k in range(w):
            if k == 0:
                u = s[j][1] + s[j-1][0] + s[j-1][1]
            elif k == w-1:
                u = s[j][k-1] +s[j-1][k-1] + s[j-1][k]
            else:
                u = s[j][k-1] +s[j][k+1] + s[j-1][k-1] + s[j-1][k] + s[j-1][k+1]
            v = u.count('#')
            if s[j][k] == '#':
                v = '#'
            t[j][k] = str(v)
    else:
         for k in range(w):
            if k == 0:
                u = s[j][1] + s[j-1][0] + s[j-1][1] + s[j+1][0] + s[j+1][1]
            elif k == w-1:
                u = s[j][k-1] +s[j-1][k-1] + s[j-1][k] + s[j+1][k-1] + s[j+1][k]
            else:
                u = s[j][k-1] +s[j][k+1] + s[j-1][k-1] + s[j-1][k] + s[j-1][k+1] + s[j+1][k-1] + s[j+1][k] + s[j+1][k+1]
            v = u.count('#')
            if s[j][k] == '#':
                v = '#'
            t[j][k] = str(v)
    print(''.join(t[j]))