#include <bits/stdc++.h>
using namespace std;
string str[2];
int n,ima;
 
 
int stoi(int &i){
  int res=0;
  while('0'<=str[ima][i]&&str[ima][i]<='9')res=res*10+str[ima][i]-'0',i++;
  return res;
}
 
 
int main(){
  while(1){
 
    cin>>str[1]>>n;
    if(str[1]=="0"&&n==0)break;
    str[0].clear();
    for(int i=0;i<str[1].size();i++) {
      if(str[1][i]=='('&&str[1][i+2]==')') str[0]+=str[1][i+1],i+=2;
      else str[0]+=str[1][i];
    }
    str[1].clear();    
 
    ima=0;
    int f=1;
    int flg=1;
    while(f){
      f=0;
      str[!ima].clear();
      for(int i=0;i<(int)str[ima].size();i++){
    if(!('0'<=str[ima][i]&&str[ima][i]<='9')) str[!ima]+=str[ima][i];
    else {
      f=1;
      int num=stoi(i);
      string pls;
      if(str[ima][i]!='(') pls+=str[ima][i];
      else {
        int c=1;
        while(c){
          i++;
          if(str[ima][i]=='(')c++;
          if(str[ima][i]==')')c--;
          if(c) pls+=str[ima][i];
        }
      }
      while(num--&&(int)str[!ima].size()<=n+1) str[!ima]+=pls;
    }
      }
       
      ima=!ima;
    }
    //cout <<str[ima]<<endl;
    if((int)str[ima].size()<=n&&flg) cout <<0<<endl;
    else cout << str[ima][n]<<endl;
  }
  return 0;
}