#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <setjmp.h>

static const char * e;
static jmp_buf      co;

static int expr ( int );

static int
term (
  const int n
  )
{
  if ( *e == '(' )
  {
    int ret;

    ++e;
    ret = expr ( n );
    ++e;

    return ( ret );
  }

  if ( n == 0 )
  {
    printf ( "%c\n", *e );
    longjmp ( co, 1 );
  }
  ++e;

  return ( 1 );
}

static int
expr (
  int n
  )
{
  int res = 0;

  for ( ; ; )
  {
    const char * b;
    int p = 0;
    int ret;

    if ( *e == ')' || *e == '\0' ) break ;

    while ( isdigit ( *e ) )
    {
      p = ( p * 10 ) + ( *( e++ ) - '0' );
    }
    p = p ? p : 1;

    b = e;
    ret = term ( n );
    if ( n >= ret && n < ret * p )
    {
      e = b;
      ret = term ( n % ret )
          + ret * ( n / ret );
    }

    res += ret * p;
    n   -= ret * p;
  }

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    char s[ 128 ];
    int n;

    scanf ( " %s %d", s, &n );
    if ( n == 0 && !strcmp ( s, "0" ) ) break ;

    e = s;
    if ( setjmp ( co ) == 0 )
    {
      expr ( n );
      puts ( "0" );
    }
  }

  return ( 0 );
}