#!/usr/bin/perl -w

use strict;
use v5.30;

my @positions;
my @npos;
while (<>) {
	my ($disc, $pos, $start) = /Disc #(\d+) has (\d+) p.* position (\d+)/;
	$disc--;
	$positions[$disc] = $start;
	$npos[$disc] = $pos;
}

push @positions, 0;
push @npos, 11;

my $t = -1;
TIME:
while (1) {
	$t++;
	for my $d (0 .. $#positions) {
		next TIME if ($positions[$d] + $t + 1 + $d) % $npos[$d];
	}
	say "$t";
	last;
}

