#include <bits/stdc++.h> // {{{

#define ARG5(a, b, c, d, NAME, ...) NAME
#define REP(...) ARG5(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define REP1(a) REP2(i, a)
#define REP2(i, a) REP3(i, 0, a)
#define REP3(i, a, b) REP4(i, a, b, 1)
#define REP4(i, a, b, s) for (int i = (a); i < (int)(b); i += (s))
#define REPR(...) ARG5(__VA_ARGS__, REPR4, REPR3, REPR2, REPR1)(__VA_ARGS__)
#define REPR1(a) REPR2(i, a)
#define REPR2(i, a) REPR3(i, 0, a)
#define REPR3(i, a, b) REPR4(i, a, b, 1)
#define REPR4(i, a, b, s) for (int i = (b)-1; i >= (int)(a); i -= (s))
#define ALL(c) (c).begin(), (c).end()
#define DUMP(x) (std::cerr << #x << ':' << ' ' << x << '\n')
#define TMPL_T template <typename T>
#define TMPL_TU template <typename T, typename U>
#define mut auto
#define let const auto

using Int = long long;
// clang-format off
namespace extio {
std::string delimiter=" ",pdelimiter=" ";
std::string bracket_b="",bracket_e="";
void chdelim(const std::string&s){delimiter=s;}
void chpdelim(const std::string&s){pdelimiter=s;}
void chbracket(const std::string&b,const std::string&e){bracket_b=b,bracket_e=e;}
TMPL_T  void pcont(std::ostream&os,const T&x){int c=0;for(const auto&a:x){if(c++)os<<delimiter;os<<a;}}
TMPL_TU void ppair(std::ostream&os,const std::pair<T,U>&p){os<<bracket_b<<p.first<<pdelimiter<<p.second<<bracket_e;}
}
namespace std {
TMPL_T ostream& operator<<(ostream&os,const vector<T>&x){extio::pcont(os,x);return os;}
TMPL_T ostream& operator<<(ostream&os,const set<T>&x){extio::pcont(os,x);return os;}
TMPL_T ostream& operator<<(ostream&os,const multiset<T>&x){extio::pcont(os,x);return os;}
TMPL_T ostream& operator<<(ostream&os,const deque<T>&x){extio::pcont(os,x);return os;}
TMPL_TU ostream& operator<<(ostream&os,const map<T,U>&x){extio::pcont(os,x);return os;}
TMPL_TU ostream& operator<<(ostream&os,const pair<T,U>&x){extio::ppair(os,x);return os;}
TMPL_T istream& operator>>(istream&is,tuple<int&,vector<T>&>x)
{int N=get<0>(x);vector<T>&v=get<1>(x);v.clear();v.reserve(N);REP(i,N){T a;is>>a;v.emplace_back(a);}return is;}
TMPL_T istream& operator>>(istream&is,tuple<vector<T>&,int&>x){return is>>tie(get<1>(x),get<0>(x));}
TMPL_T istream& operator>>(istream&is,tuple<int&,T*>x){int N=get<0>(x);T*v=get<1>(x);REP(i,N){is>>v[i];}return is;}
TMPL_T istream& operator>>(istream&is,tuple<T*,int&>x){return is>>tie(get<1>(x),get<0>(x));}
}
TMPL_TU inline bool chmax(T&x,U a){return x<a&&(x=a,1);}
TMPL_TU inline bool chmin(T&x,U a){return a<x&&(x=a,1);}

inline int in(){int x;std::cin>>x;return x;}

struct Initializer_ {
  Initializer_(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(0);
    std::cout << std::setprecision(10);
    std::cerr << std::setprecision(10);
  }
} precalc;
// clang-format on
// }}}

#include <ext/rope>

using namespace std;
using Rope = __gnu_cxx::rope<char>;
using siter = std::string::iterator;

inline void consume(siter& it, char expected) {
  if (expected == *it) {
    ++it;
    return;
  }
  cerr << "Error:\n";
  cerr << "Expected: " << expected << '\n';
  cerr << "Actual:   " << *it << '\n';
  ++it;
  cerr << "Rest string: ";
  while (*it) {
    cerr << *it;
    ++it;
  }
  cerr << '\n';
}
Rope token(siter& it);
Rope eval(siter& it) {
  Rope rope;
  int r = 0;
  while (*it != ')' && *it != '\0') {
    auto t = token(it);
    if (rope.size() < 1000100) { rope += t; }
  }
  return rope;
}
Rope token(siter& it) {
  int r = 0;
  while (isdigit(*it)) {
    r = r * 10 + *it - '0';
    ++it;
  }
  if (r == 0) r = 1;
  Rope rope;
  if (*it == '(') {
    consume(it, '(');
    rope = eval(it);
    consume(it, ')');
  } else {
    rope.push_back(*it);
    ++it;
  }
  Rope res;
  REP(i, r) {
    if (res.size() < 1000100) { res += rope; }
  }
  return res;
}

signed main() {
  string s;
  int p;
  while (cin >> s >> p) {
    if (s == "0" && p == 0) break;
    auto it = s.begin();
    Rope rope = eval(it);
    if (rope.size() <= p) {
      cout << 0 << endl;
    } else {
      cout << rope[p] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 12116