# use strict; # use warnings; chomp(my $x = <>); my ($N, $K) = split(/ /, $x); chomp(my $S = <>); my @ns = 1 .. $N; $_ = $S; while (s/\(\)//) { if ($ns[$-[0]] == $K) { print($ns[$-[0] + 1], "\n"); exit; } if ($ns[$-[0] + 1] == $K) { print($ns[$-[0]], "\n"); exit; } splice(@ns, $-[0], 2); } exit 1;