#!/usr/bin/perl -w

use v5.20;
use strict;

my $input = shift @ARGV;

my $r = '37';
my @p = qw(0 1);

my $l = length $input;
my $lr = length $r;
while (1) {
	my @n = (substr($r, $p[0], 1), substr($r, $p[1], 1));
	$r .= $n[0]+$n[1];
	$lr = length $r;
	for (0 .. 1) {
		$p[$_] += 1 + $n[$_];
		$p[$_] -= $lr while $p[$_] >= $lr;
	}
	next if $lr < $l;
	last if substr($r, -$l) eq $input;
	last if substr($r, -$l-1, -1) eq $input;
}

$r =~ s/$input.*//;
say length $r;
