#ifndef _WIN32
#include<iostream>
#endif

using namespace std;
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<string.h>


#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

typedef vector<int> V;
typedef vector<V> VV;
typedef long long LL;
template<typename T>
bool chmin(T &l, T r) {
	bool f = l > r; if (f)l = r; return f;
}
template<typename T>
bool chmax(T &l, T r) {
	bool f = l < r; if (f)l = r; return f;
}
VV wrap(VV vs, int c) {
	int R = vs.size();
	int C = vs[0].size();
	VV ret(R + 2, V(C + 2, c));
	REP(i, R)REP(j, C)ret[i + 1][j + 1] = vs[i][j];
	return ret;
}
const int dr[] = { 0,0,-1,1 ,1,1,-1,-1 };
const int dc[] = { -1,1,0,0, -1,1,-1,1 };
string S;
int id;
VV g;
LL rep[1123];
LL len[1123];
char type[1123];
LL parseInt() {
	LL ret = 0;
	while (isdigit(S[id])) {
		ret *= 10;
		ret += S[id] - '0';
		id++;
	}
	return ret;
}
V parse() {
	V ret;
	id++;
	while (S[id] != ')') {
		g.push_back({});
		int v = g.size();
		ret.push_back(v);
		if (isdigit(S[id])) {
			rep[v] = parseInt();
			if (S[id] == '(') {
				type[v] = '-';
				g[v] = parse();
			}
			else {
				type[v] = S[id++];
			}
		}
		else {
			rep[v] = 1;
			type[v] = S[id++];
		}
	}
	id++;
	return ret;
}
const LL INF = 1e9;
LL dfs(int v) {
	if (type[v] == '-') {
		len[v] = 0;
		for (auto &it : g[v])len[v] += dfs(it);
		chmin(len[v], INF);
	}
	else {
		len[v]=1;
	}
	return min(len[v]*rep[v],INF);
}
char f(int v,LL x){
	if (type[v] == '-') {
		x %= len[v];
		for (auto &u : g[v])
			if (x < len[u] * rep[u])return f(u, x);
			else x -= len[u] * rep[u];
	}
	else {
		return type[v];
	}

}
int main() {
	LL x;
	while (cin >> S >> x, S != "0") {
		S = "(" + S + ")";
		id = 0;
		g.clear();
		g.push_back({});
		rep[0] = 1;
		type[0] = '-';
		g[0] = parse();
		LL all=dfs(0);
		if (all <= x)cout << 0 << endl;
		else cout << f(0,x) << endl;
	}




}