#!/usr/bin/perl -w

use strict;

my $rounds;
($rounds, $_) = @ARGV;
$_ .= '3' x 10_000_000;

while ($rounds--) {
	my ($cur) = /\A(.)/;
	do {
		$cur--;
		$cur = 9 if $cur == 0;
	} while (/\A.{1,3}$cur/);
	
	s/\A(.)(...)(.*)$cur(.*)\z/$3$cur$2$4$1/;
	# print $_, "\n";
}

s/\A(.*)1(.*)\z/Result is $2$1\n/;
print;
