my $N = <STDIN>;
chomp($N);
my @a;
my $t;
for (1..$N){
    $t = <STDIN>;
    push(@a,$t);
}

my ($f,$s) = (0,0);
for (@a){
    if($_ > $f){$f = $_;}
}
for (@a){
    if($_ > $s && $f > $_){$s = $_;}
}
if($s == 0){$s = $f};

for (@a){
    if($_ < $f){print "$f";}
    else {print "$s";}
}
1;
