#!/usr/bin/perl

use v5.30;
use strict;

my $in = 345;

my @buffer = (0);
my $pos = 0;
for (1 .. 2017) {
	# say "$_ $pos ", join(',', @buffer);
	$pos += $in;
	if (@buffer > 1) {
		$pos %= scalar @buffer;
	} else {
		$pos = 0;
	}
	$pos++;
	splice @buffer, $pos, 0, $_;
}

say $buffer[$pos+1];

