#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdlib>
#include <vector>
#include <map>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)

string Str;
int Index;

class Node {
public:
  int num;
  string s;
  vector<Node> v;
  Node() { num = -1; }
};

Node root;

int getNum(int &pos, string s) {
  int st = pos;
  int length = 0;
  while(isdigit(s[pos])) { ++length; ++pos; }
  //cout << s << " => " << s.substr(st, length) << endl;
  return atoi(s.substr(st, length).c_str());
}

char rec(int &i, int j, Node node) {
  //cout << node.s << " :: " << node.num << endl;
  if(node.s.size()) {
    for(int l = 0; l < node.num; ++l) {
      for(int k = 0; k < node.s.size(); ++k) {
	//cout << node.s[k];
	if(i == j) return node.s[k];
	++i;
      }
    }
    return '0';
  }

  for(int k = 0; k < node.num; ++k) {
    for(int l = 0; l < node.v.size(); ++l) {
      char c = rec(i, j, node.v[l]);
      if(c != '0') return c;
    }
  }
  return '0';
}

vector<string> sep(string s)
{
  string t = "";
  vector<string> v, u;
  t += s[0];

  for(int i=1; i<s.size(); ++i){
    if(s[i-1] == ')') {
      v.push_back(t);
      t = "";
    }
    /*
    if( s[i-1] == ')' && isalpha(s[i]) ){
      v.push_back(t);
      t = "";
    }
    else if( s[i-1] == ')' && isdigit(s[i]) ){
      v.push_back(t);
      t = "";
    }
    else if( isdigit(s[i]) && isalpha(s[i-1])){
      v.push_back(t);
      t = "";
      }*/
    t += s[i];
  }
  if(t.size()) {
    v.push_back(t);
  }

  int o, c;
  o = c = 0;
  t = "";
  for(int i = 0; i < v.size(); ++i) {
    if(o + c && o == c) {
      u.push_back(t);
      o = c = 0;
      t = "";
    }
    t += v[i];
    o += count(v[i].begin(), v[i].end(), '(');
    c += count(v[i].begin(), v[i].end(), ')');
  }
  if(t.size()) u.push_back(t);
  return u;
  for(int i=0; i<u.size(); ++i){
    cout << u[i] << "_";
  }
  cout << endl;
  return u;
}

void conv(string &s) {
  {
    bool flag = true;
    for(int i = 0; i < s.size(); ++i) {
      if(!isalpha(s[i])) {
	flag = false;
	break;
      }
    }
    s.insert(0, "1(");
    s.insert(s.size(), ")");
    if(flag) {
      return;
    }
  }
  for(int i = 1; i < s.length(); ++i) {
    if((s[i-1] == ')' || s[i-1] == '(' ) && isalpha(s[i])) {
      int p = i;
      while(true) {
	if(!isalpha(s[p])) {
	  if(s[i-1] == '(' && s[p] == ')') break;
	  s.insert(i, "1(");
	  s.insert(p+2, ")");
	  i = p+2;
	  break;
	}
	++p;
      }
    }
  }
  for(int i = 1; i+1 < s.length(); ++i) {
    if(isdigit(s[i-1]) && isalpha(s[i])) {
      s.insert(i, "(");
      s.insert(i+2, ")");
    }
  }
}

Node build(string s) {
  //cout << s << endl;
  Node node;
  int num;
  if(isalpha(s[0])) {
    node.num = 1;
    node.s = s;
    return node;
  } else {
    int pos = 0;
    num = getNum(pos, s);
    /*
    if(s[pos] != '(') {
      node.num = num;
      node.s = "";//(pos < s.size()) ? "####" : "@@@";
      node.s += s[pos];
      return node;
      }*/
    ++pos;
    s.erase(s.begin(), s.begin()+pos);
    s.erase(s.begin() + s.size() - 1);

    /*if(count(s.begin(), s.end(), '(') == 0) {
      node.num = num;
      node.s = s;
      return node;
      }*/
    int o, c;
    string t = "";
    o = c = 0;
    vector<string> v = sep(s);
    for(int i=0; i<v.size(); ++i){
      node.v.push_back( build(v[i]) );
    }
  }  
  node.num = num;
  return node;
  cout << node.s << endl;
  for(int i = 0; i < node.v.size(); ++i) {
    cout << node.v[i].s << " ";
  }
  cout << endl << endl;
  return node;
}

void solve() {
  conv(Str);
  //cout << Str << endl;
  root = build(Str);
  int i = 0;
  char c  = rec(i, Index, root);
  cout << c << endl;
}

main() {
  while(cin >> Str >> Index) {
    if(Str == "0" && Index == 0) break;
    solve();
  }
}

Measured memory_bytes: 964