#!/usr/bin/perl -w

use v5.30;
use strict;

my $iters = shift @ARGV;
$iters += 10;

my @r = qw(3 7);
my @p = qw(0 1);

while (@r < $iters) {
	my $n = $r[$p[0]] + $r[$p[1]];
	push @r, split //, $n;
	for (0 .. 1) {
		$p[$_] += 1 + $r[$p[$_]];
		$p[$_] -= @r while $p[$_] >= @r;
	}
	# say join ' ', @p, @r;
}

say join('', @r[-10 .. -1])

