#!/usr/bin/python3
import sys
import fileinput

grid = {}
xmin, xmax = 500, 500
ymin, ymax = 0, 0

def put(x, y, char):
	global grid, xmin, xmax, ymin, ymax
	if x > xmax:
		xmax = x
	if x < xmin:
		xmin = x
	if y > ymax:
		ymax = y
	if y < ymin:
		ymin = y
	grid[(x,y)] = char

def show():
	global grid, xmin, xmax, ymin, ymax
	for y in range(ymin, ymax+1):
		line = ""
		for x in range(xmin, xmax+1):
			if (x,y) not in grid:
				put(x, y, '.')
			line += grid[(x,y)]
		print(line)

def drop(x, y):
	global grid, ymax
	while y < ymax:
		if (x-1,y+1) not in grid:
			put(x-1, y+1, '.')
		if (x,y+1) not in grid:
			put(x, y+1, '.')
		if (x+1,y+1) not in grid:
			put(x+1, y+1, '.')
		if grid[(x,y+1)] == '.':
			y += 1
		else:
			if grid[(x-1,y+1)] == '.':
				x -= 1
				y += 1
			elif grid[(x+1,y+1)] == '.':
				x += 1
				y += 1
			else:
				put(x, y, 'o')
				return True
	return False


for line in fileinput.input():
	pairs = line.rstrip().split(' -> ')
	first = True
	for pair in pairs:
		x, y = list(map(int, pair.split(',')))
		if first:
			px, py = x, y
			first = False
			continue
		if px == x:
			if py < y:
				for yy in range(py, y+1):
					put(x, yy, '#')
			else:
				for yy in range(y, py+1):
					put(x, yy, '#')
		elif py == y:
			if px < x:
				for xx in range(px, x+1):
					put(xx, y, '#')
			else:
				for xx in range(x, px+1):
					put(xx, y, '#')
		px, py = x, y

# drop(500,0); drop(500,0); drop(500,0); drop(500,0); drop(500,0)
# show()
# sys.exit(0)

sand = 0
while drop(500, 0):
	sand += 1
print(sand)