#include <iostream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;

int n;
const char *p;

string parse(){
	string s;
	while(1){
		if(isalpha(*p)){
			s += *p++;
		}
		else if(isdigit(*p)){
			char *endp;
			int k = strtol(p, &endp, 10);
			p = endp;

			string t(1, 0);
			if(*p == '('){
				++p;
				t = parse();
				++p;
			}
			else{
				t[0] = *p++;
			}

			for(int i = 0; i < k && s.size() <= n; ++i){
				s += t;
			}
		}
		else{
			break;
		}
		
		if(s.size() > n + 1){
			s.resize(n + 1);
		}
	}
	return s;
}

int main(){
	string s;
	while(cin >> s >> n, s != "0"){
		p = s.c_str();
		s = parse();
		cout << (n < s.size() ? s[n] : '0') << endl;
	}
}