i, j = [int(x) for x in raw_input().split()]
l = []
for x in xrange(i):
	l.append(list(raw_input()))
o = []
for x in xrange(i):
	for y in xrange(j):
		if l[x][y] == '#':
			o.append('#')
			continue
		#is '.'
		temp = 0
		for d_x in xrange(-1, 2):
			for d_y in xrange(-1, 2):
				if x + d_x < 0 or x + d_x >= i or y + d_y < 0 or y + d_y >= j:
					continue
				try:
					if l[x + d_x][y + d_y] == '#':
						temp += 1
				except:
					continue
		s = 0
		o.append(str(temp))
	o.append('\n')
print ''.join(o[:-1])