#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem1145 : The Genome Database of All Space Life**/
string s, ret;
int pos, idx;
// <code> := <num> <c> | <num> ( <code> ) | <num> ( <code> <code> ) | ...
// <num> := <digit> | <digit> <num>
// <c> := A | B | ... | Z

string factor()
{
	if ('A' <= s[pos] && s[pos] <='Z') {
		
	}
}

string formula()
{
	string ret="";
	
	if ('A' <= s[pos] && s[pos] <= 'Z') {
		ret = s[pos];
		pos++;
	} else if (isdigit(s[pos])) {
		int num = 0;
		while (isdigit(s[pos])) {
			num*=10;
			num+=s[pos]-'0';
			pos++;
		}
		string ss = formula();
		rep(i, num) {
			ret += ss;
			if (ret.size()>idx)
				break;
		}
	} else if (s[pos] == '(') {
		pos++;
		while (s[pos] != ')') {
			ret += formula();
		}
		pos++;
	}
	
	return ret;
}

int main()
{
	while (cin>>s>>idx, s!="0"||idx) {
		pos = 0;
		ret = "";
		
		while (pos != s.size()) {
			ret += formula();
			if (ret.size() > idx)
				break;
		}
		
		if (idx>=ret.size())
			cout << 0 << endl;
		else
			cout << ret[idx] << endl;
	}
}