#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

ll roc = 0;
string s;
ll i;
ll t;
bool found = false;
char ans = '#';

string genome() {
	string res = "";
	if(s[roc] == '(') {
		++roc;
		while(s[roc] != ')' && !found) {
			if(s[roc] >= 'A' && s[roc] <= 'Z') {
				res += s[roc];
				++t;
				if(t == i && ans == '#') {
					ans = s[roc];
					found = true;
					++roc;
					t = INF;
					break;
				}
				++roc;
			} else {
				ll roc_buf = roc;
				while(s[roc] >= '0' && s[roc] <= '9') ++roc;
				int roop = stoi(s.substr(roc_buf, roc - roc_buf));
				string rooped = genome();
				if(!found) {
					REP(j, roop - 1) {
						if(t + rooped.size() < i) {
							t += rooped.size();
							res += rooped;
						} else {
							if(ans == '#') {
								ans = rooped[(i - t) - 1];
								found = true;
								t = INF;
							}
							break;
						}
					}
					res += rooped;
				}
			}
		}
		++roc;
		return res;
	} else {
		res += s[roc];
		++t;
		if(t == i) {
			ans = s[roc];
			found = true;
		}
		++roc;
		return res;
	}
}

int main(void) {
	while(true) {
		cin>>s>>i;
		if(s == "0" && i == 0) break;
		roc = 0;
		t = -1;
		found = false;
		ans = '#';
		s = "(" + s;
		s += ")";
		genome();
		if(ans == '#') cout<<0<<endl;
		else cout<<ans<<endl;
	}
}