from sys import stdin


def manhattan_distance(a, b):
	ax, ay = a
	bx, by = b

	return abs(bx - ax) + abs(by - ay)


def tuning_frequency(position):
	x, y = position
	return 4000000 * x  + y


def parse_coord(s):
	_, s = s.split("=")
	return int(s)


def parse_point(s):
	x, y = s.split(",")
	return parse_coord(x), parse_coord(y)


def parse_sensor(line):
	sensor, beacon = line.split(":")
	return parse_point(sensor), parse_point(beacon)


def generate_horizon(sensor, beacon):
	sx, sy = sensor
	min_distance = manhattan_distance(sensor, beacon)

	for dx in range(0, min_distance + 2):
		dy = min_distance - dx + 1

		yield sx + dx, sy + dy
		yield sx - dx, sy + dy
		yield sx - dx, sy - dy
		yield sx + dx, sx - dy


def solve(sensors):
	horizon = set()

	for sensor, beacon in sensors.items():
		for p in generate_horizon(sensor, beacon):
			x, y = p

			if 0 <= x <= 4000000 and 0 <= y <= 4000000:
				visible = False

				for s, b in sensors.items():
					if manhattan_distance(p, s) <= manhattan_distance(s, b):
						visible = True
						break

				if not visible:
					return tuning_frequency(p)


def main():
	sensors = {}

	for line in stdin:
		sensor, beacon = parse_sensor(line)
		sensors[sensor] = beacon

	print(solve(sensors))


if __name__ == "__main__":
	main()
