#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'for_list';

my @map;

while (<>) {
	my @list = /(\d+)/g;
	my ($x0, $y0) = splice @list, 0, 2;
	$map[$y0][$x0] = 1;

	for my ($x, $y) (@list) {
		while ($x0 != $x || $y0 != $y) {
			$x0 += $x <=> $x0;
			$y0 += $y <=> $y0;
			$map[$y0][$x0] = 1;
		}
	}
}
my $maxy = @map;

my $units = 0;
while (!$map[0][500]) {
	my ($x, $y) = (500, 0);

	while ($y < $maxy) {
		if (!$map[$y+1][$x]) {
			$y++;
		} elsif (!$map[$y+1][$x-1]) {
			$x--; $y++;
		} elsif (!$map[$y+1][$x+1]) {
			$x++; $y++;
		} else {
			last;
		}
	}
	$map[$y][$x] = 2;
	$units++;
}

say $units;
