#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

string s;
int n;
int m;
char solve(){
    stack<pair<int,string> > q;
    stack<int> st;
    string tmp;
    int dep = 0;
    for(int i=0;i<m;i++){
        bool flag = 0;
        int k = 0;
        while(isdigit(s[i])){
            flag = 1;
            k *=10;
            k += s[i]-'0';
            i++;
        }
        if(flag){
            if(s[i]=='('){
                st.push(tmp.size());
                n -= tmp.size();
                q.push(MP(k,tmp));
                tmp = "";
                dep++;
            }else{
                string tmp2(k,s[i]);
                tmp += tmp2;
                if((int)tmp.size()-1>=n){
                    return tmp[n]; 
                }
            }
        }else{
            if(s[i]==')'){
                dep--;
                int y = st.top();
                st.pop();
                n += y;
                auto xx = q.top();
                q.pop();
                int p = xx.first;
                string t = xx.second;
                if(t.size()+p*(int)tmp.size()-1>=n){
                    n -= t.size();
                    int id = n % tmp.size();
                    return tmp[id];
                }else{
                    string tmp2 = t;
                    rep(zz,p){
                        tmp2 += tmp;
                    }
                    tmp = tmp2;
                    if(dep==0){
                        n -= tmp.size();
                        tmp = "";
                    }
                }
            }else{
                tmp.push_back(s[i]);
            }
        }
    }
    if((int)tmp.size()-1<n){
        return '0';
    }else{
        return tmp[n];
    }
}

int main(){
    while(cin >> s >> n){
        if(s=="0"&&n==0)break;
        m = s.size();
        cout << solve() << endl;
    }
    return 0;
}
