#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
struct Token {
  int ty;
  int val;
  string str;
  Token() {}
  Token(int ty, int val, string str): ty(ty) {
    if(ty == 2) {
      this->val = val;
      this->str = "";
    } else if(ty == 3) {
      this->val = -1;
      this->str = str;
    } else {
      this->val = -1;
      this->str = "";
    }
  }
};
void lex(string s, vector<Token> &tokens) {
  int nowval = 0;
  string nowstr = "";
  for(int i=0;i<(int)(s.size());++i) {
    if(s[i] == '(') {
      if(nowval != 0) {
        tokens.emplace_back(Token(2, nowval, nowstr));
        nowval = 0;
      } else if(nowstr != "") {
        tokens.emplace_back(Token(3, nowval, nowstr));
        nowstr = "";
      }
      tokens.emplace_back(Token(0, -1, ""));
    } else if(s[i] == ')') {
      if(nowval != 0) {
        tokens.emplace_back(Token(2, nowval, nowstr));
        nowval = 0;
      } else if(nowstr != "") {
        tokens.emplace_back(Token(3, nowval, nowstr));
        nowstr = "";
      }
      tokens.emplace_back(Token(1, -1, ""));
    } else if('0' <= s[i] && s[i] <= '9') {
      if(nowstr != "") {
        tokens.emplace_back(Token(3, nowval, nowstr));
        nowstr = "";
      }
      nowval *= 10;
      nowval += s[i] - '0';
    } else {
      if(nowval != 0) {
        tokens.emplace_back(Token(2, nowval, nowstr));
        nowval = 0;
      }
      nowstr.push_back(s[i]);
    }
  }
  if(nowval != 0) {
    tokens.emplace_back(Token(2, nowval, nowstr));
  } else if(nowstr != "") {
    tokens.emplace_back(Token(3, nowval, nowstr));
  }
}
pair<int, char> solve(const vector<Token> &tokens, int now, int &cnt, int k) {
  for(int i=now;i<(int)(tokens.size());++i) {
    if(tokens[i].ty == 1) {
      return {i, '*'};
    } else if(tokens[i].ty == 2) {
      int sz = tokens[i].val;
      int nxt = i;
      for(int j=0;j<sz;++j) {
        auto res = solve(tokens, i+1, cnt, k);
        if(res.second != '*') {
          return {-1, res.second};
        } else {
          nxt = res.first;
        }
      }
      i = nxt;
    } else if(tokens[i].ty == 3) {
      if(cnt + (int)(tokens[i].str.size()) > k) {
        return {-1, tokens[i].str[k - cnt]};
      } else {
        cnt += (int)(tokens[i].str.size());
      }
    }
  }
  return {1000000, '*'};
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    string s; cin >> s;
    int k; cin >> k;
    if(s == "0" && k == 0) break;
    vector<Token> tokens;
    lex(s, tokens);
    vector<Token> tokens2;
    tokens2.emplace_back(2, 1, "");
    tokens2.emplace_back(0, 0, "");
    for(int i=0;i<(int)(tokens.size());++i) {
      if(tokens[i].ty == 3 && (i == 0 || (tokens[i-1].ty != 0 && tokens[i-1].ty != 2))) {
        tokens2.emplace_back(2, 1, "");
        tokens2.emplace_back(0, 0, "");
        tokens2.emplace_back(tokens[i]);
        tokens2.emplace_back(1, 0, "");
      } else if(tokens[i].ty == 3 && (i == 0 || (tokens[i-1].ty == 2))) {
        tokens2.emplace_back(0, 0, "");
        tokens2.emplace_back(tokens[i]);
        tokens2.emplace_back(1, 0, "");
      } else {
        tokens2.emplace_back(tokens[i]);
      }
    }
    tokens2.emplace_back(1, 0, "");
    int cnt = 0;
    auto res = solve(tokens2, 0, cnt, k);
    if(res.second == '*') {
      cout << 0 << endl;
    } else {
      cout << res.second << endl;
    }
  }
}



Measured memory_bytes: 3252