#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
//I referred to other's code.
const int MAX_L = 10000001;
string s;
int needidx;
string expr(int& p);
int num(int& p){
  int res = 0;
  while(isdigit(s[p])){
    res = res * 10 + (s[p++] - '0');
  }
  return res;
}
string chara(int& p){
  string res = "";
  while(isalpha(s[p])){
    res += s[p++];
  }
  return res;
}
string term(int& p){
  string res;
  if(isalpha(s[p])){
    res =  chara(p);
  }else{
    int n = num(p);
    string t;
    if(s[p]=='('){
      p++;
      t = expr(p);
      p++;
    }else{
      t = chara(p);
    }
    REP(i,n){
      if(res.size() > needidx) break;
      res += t;
    }
  }
  return res;
}
string expr(int& p){
  string res = term(p);
  while(p < s.size() && s[p] != ')'){
    if(res.size() > needidx) break;
    res += term(p);
  }
  return res;
}

int main(){
  while(cin>>s>>needidx, s!="0"){
    int p = 0;
    string ans = expr(p);
    if(ans.size() > needidx){
      cout<<ans[needidx]<<endl;
    }else{
      cout<<0<<endl;
    }
  }
  return 0;
}