// www.hackerearth.com/submission/8387337/
import java.util.*;
class javaFile{
private static final char L = '(';
private static final char R = ')';
private static int l = 0;
private static int index = 0;
public static void main
(String args
[]){ Scanner sc
= new Scanner
(System.
in); Stack<Character> st = new Stack<>();
s = sc.next();
int n = sc.nextInt();
l = s.length();
int count = 0,i=0;
if(n==2){
for(i = 0;i<l;i++)
{
if(s.charAt(i)==L)
{
if(st.isEmpty())
{
count=0;
}
st.push(L);
count++;
}
else if(s.charAt(i)==R)
{
st.pop();
}
}
}
else if(n==1)
{
for(i = l-1;i>=0;i--)
{
if(s.charAt(i)==R)
{
if(s.isEmpty())
{
count=0;
}
st.push(R);
count++;
}
else if(s.charAt(i)==L)
{
st.pop();
}
}
}
}
}
Ly8gd3d3LmhhY2tlcmVhcnRoLmNvbS9zdWJtaXNzaW9uLzgzODczMzcvCgppbXBvcnQgamF2YS51dGlsLio7CmNsYXNzIGphdmFGaWxlewogICAgcHJpdmF0ZSBzdGF0aWMgZmluYWwgY2hhciBMID0gJygnOwogICAgcHJpdmF0ZSBzdGF0aWMgZmluYWwgY2hhciBSID0gJyknOwogICAgcHJpdmF0ZSBzdGF0aWMgaW50IGwgPSAwOwogICAgcHJpdmF0ZSBzdGF0aWMgaW50IGluZGV4ID0gMDsKICAgIHByaXZhdGUgc3RhdGljIFN0cmluZyBzID0gIiI7CiAKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZyBhcmdzW10pewogICAgICAgIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAgICAgIFN0YWNrPENoYXJhY3Rlcj4gc3QgPSBuZXcgU3RhY2s8PigpOwogICAgICAgIHMgPSBzYy5uZXh0KCk7CiAgICAgICAgaW50IG4gPSBzYy5uZXh0SW50KCk7CiAgICAgICAgbCA9IHMubGVuZ3RoKCk7CiAgICAgICAgaW50IGNvdW50ID0gMCxpPTA7CiAgICAgICAgICAgIGlmKG49PTIpewogICAgICAgICAgICAgICAgZm9yKGkgPSAwO2k8bDtpKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaWYocy5jaGFyQXQoaSk9PUwpCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBpZihzdC5pc0VtcHR5KCkpCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdW50PTA7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgc3QucHVzaChMKTsKICAgICAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZSBpZihzLmNoYXJBdChpKT09UikKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0LnBvcCgpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKG49PTEpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZvcihpID0gbC0xO2k+PTA7aS0tKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGlmKHMuY2hhckF0KGkpPT1SKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYocy5pc0VtcHR5KCkpCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdW50PTA7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgc3QucHVzaChSKTsKICAgICAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZSBpZihzLmNoYXJBdChpKT09TCkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0LnBvcCgpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oY291bnQpOwogICAgfQp9