import sys G = [ list(l[:-1]) for l in sys.stdin.readlines()] W = len(G[0]) H = len(G) def get_G(x,y): return '.' if x<0 or y<0 or x>W-1 or y>H-1 else G[y][x] def is_sym(a:str) -> bool: return a != '.' and not a.isdigit() S = 0 c = 0 # current valid = False for y in range(H): for x in range(W): i = get_G(x,y) if not i.isdigit(): if valid: S += c valid = False c = 0 else: c = c*10+int(i) for dx in [-1,0,1]: for dy in [-1,0,1]: valid |= is_sym(get_G(x+dx,y+dy)) print(S)