h,w = map(int, raw_input().split())
c = '.'*(w+2)
mass = []
mass.append(c)
for _ in xrange(h):
    s = '.' + raw_input() + '.'
    mass.append(s)
mass.append(c)

ans = [['.' for _ in xrange(w)] for _ in xrange(h)]
for i in xrange(h):
    for j in xrange(w):
        if mass[i+1][j+1] == '#':
            ans[i][j] = '#'
        else:
            count = 0
            for a in [-1, 0, 1]:
                for b in [-1, 0, 1]:
                    if mass[i+1+a][j+1+b] == '#': count += 1
            ans[i][j] = str(count)

for x in ans:
    print "".join(x)