/*
AizuOnline A1145
Title The Genome Database of All Space Life
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
char s[101];
int  idx;
int node_ptr;
struct NODE
{
  int car;
  int cdr;
  char * genum;
  int glen;       // mojiretu no nagasa
  int blen;       // tenkai go no nagasa
  int coef;       // keisuu < 5keta
} Gnode[100];

//
int is_under_5digits(char * g)
{
  int i;

  for(i=0;i<5;i++)
    if(!isdigit(g[i]))
      return(i);
 
  return(5);
}
int get_close_paren(char * g)
{
  char *p;
  int depth;
#ifdef DEBUG2
  printf("gcp=%s\n",g);
#endif
  depth=0;
  for(p=g;*p;p++)
    {
      if(*p=='(')
	depth++;
      if(*p==')')
	depth--;
      if(depth==0)
	{
#ifdef DEBUG2
  printf("gcpA=%d\n",p-g);
#endif
	return(p-g);
	}
    }
  return(-1);
} 
int get_1st(char * g,int l)
{
  int ret;
  int i;
  
  if(isupper(g[0]))
    {
      for(i=0;i<l;i++)
	if(!isupper(g[i+1]))
	  return(i+1);
      
      return(l);
    }
  if(ret=is_under_5digits(g))
    {
#if DEBUG2
      printf("NL=%d\n",ret);
#endif
      if(isalpha(g[ret]))
	return(ret+1);
      if(g[ret]=='(')
	return(ret+1+get_close_paren(g+ret));
    }
}
int is_single(char * g,int l)
{
  if(l==1)
    return(isupper(g[0]));
  else
    return(isupper(g[0]) && is_single(g+1,l-1));
}
int all_upper(char * g,int len)
{
  int i;

  for(i=0;i<len;i++)
    if(!isupper(g[i]))
      return(0);

  return(-1);
}
int get_times(char * g,char len)
{
  int i,c;
  //printf("T:%s %d\n",g,len);
  c=0;
  for(i=0;i<len;i++)
    {
      c*=10;
      c+=(g[i]-'0');
    }
  return(c);
}
int get_len_leaf()
{

}

int get_len_recursive(int ndp)
{
  int ret;

  if(Gnode[ndp].cdr == -1)
    {
      if(Gnode[ndp].car == -1)
	{
	  if(Gnode[ndp].coef > 1)
	    ret=Gnode[ndp].coef;
	  else
	    ret=Gnode[ndp].glen;
	  //printf("Le:%d\n",ret);
	  Gnode[ndp].blen=ret;
	  return(ret);
	}
      else
	{
	  ret=get_len_recursive(Gnode[ndp].car)*Gnode[ndp].coef;
	  Gnode[ndp].blen=ret;
	  return(ret);
	}
    }
  else
    {
        ret=get_len_recursive(Gnode[ndp].car);
	ret+=get_len_recursive(Gnode[ndp].cdr);
	Gnode[ndp].blen=ret;
	return(ret);
    }
}

void print_all_node()
{
  int i,j;

  for(i=0;i<=node_ptr;i++)
    {
      printf("%d:",i);
      printf("[%d]",Gnode[i].coef);
      printf("(%d)",Gnode[i].blen);
      if(Gnode[i].car>0)
	printf("%d:",Gnode[i].car);
      else
	printf("*:");
      if(Gnode[i].cdr>0)
	printf("%d:",Gnode[i].cdr);
      else
	printf("*:");
      
      for(j=0;j<Gnode[i].glen;j++)
	{
	  printf("%c",Gnode[i].genum[j]);
	}
      printf("\n");
    }
}
void set_node(int n,char * g,int len)
{
  int ret;
  //printf("G:%d %s %d\n",n,g,len);
  Gnode[n].car = -1;
  Gnode[n].cdr = -1;

  Gnode[n].genum = g;
  Gnode[n].glen = len;
}

int get_new_node()
{
  node_ptr++;
  Gnode[node_ptr].coef=1;
  return(node_ptr);
}

void set_nodes_recursive(int ndp,char * g,int gl)
{
  int l1,carp,cdrp,ret;
    
  //printf("g %s gl %d\n",g,gl);
  set_node(ndp,g,gl);
  
  l1=get_1st(g,gl);

  if(l1 < gl)
    {
      carp=Gnode[ndp].car = get_new_node();
      cdrp=Gnode[ndp].cdr = get_new_node();
      set_nodes_recursive(carp,g,l1);
  
      set_nodes_recursive(cdrp,&g[l1],gl-l1);
    }
  else if(ret=is_under_5digits(g))
    {
      Gnode[ndp].coef=get_times(g,ret);
      if(g[ret]=='(')
	{
	  carp=Gnode[ndp].car = get_new_node();
	  Gnode[ndp].cdr = -1;
      //printf("tims %d\n",get_times(g,ret));
	  set_nodes_recursive(carp,g+ret+1,gl-ret-2);
	}
      else
	{
	  Gnode[ndp].car = -1;
	  Gnode[ndp].genum +=ret;
	  Gnode[ndp].glen  -=ret;
	}
    }
}
void set_all_node()
{
  set_nodes_recursive(0,s,strlen(s));
}

void get_len_all()
{
  get_len_recursive(0);
}
char get_bunsi(int ndp,int id)
{
  struct NODE *np;
  np=&Gnode[ndp];
#ifdef DEBUG  
  printf("N,I=%d %d\n",ndp,id);
#endif
  if(np->blen <= id)
    return('0');
  if(np->cdr == -1)
    {
      if(np->car == -1)
	{
	  if(np->coef > 1)
	    {
	      return(np->genum[0]);
	    }
	  else
	    return(np->genum[id]);
	}
      else
	return(get_bunsi(np->car,id % Gnode[np->car].blen));
    }
  if(Gnode[np->car].blen > id)
    return(get_bunsi(np->car,id));
  else
    return(get_bunsi(np->cdr,id-Gnode[np->car].blen));
}

main()
{
  while(EOF!=scanf("%s %d",s,&idx) && !(s[0]=='0' && s[1]=='\0' && idx==0))
    {
      node_ptr=0;
      set_all_node();
      get_len_all();
#ifdef DEBUG
      print_all_node();
#endif
      printf("%c\n",get_bunsi(0,idx));
    }

return(0);
}