Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.

Input

The first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109) — the number defining the masses of the weights and the mass of the item.

Output

Print word 'YES' if the item can be weighted and 'NO' if it cannot.

Examples

Input

3 7


Output

YES


Input

100 99


Output

YES


Input

100 50


Output

NO

Note

Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.

Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.

Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input. 
import java.util.*;
import java.io.*;

public class Solution
{
       static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(
                new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    if (cnt != 0) {
                        break;
                    }
                    else {
                        continue;
                    }
                }
                buf[cnt++] = (byte)c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0,
                                 BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    static int parent(int x , int p[])
    {
           if(p[x] == x)
           return x;
           
           return (p[x] = parent(p[x],p));
    }
    
    static void union(int a , int b , int p[] , int size[])
    {
           a = parent(a,p);
           b = parent(b,p);
           
           if(size[a] < size[b])
           {
                  int temp = a;
                  a = b;
                  b = temp;
           }
           p[b] = a;
           size[a] += size[b];
    }
    
   
  
  static int max(int x)
  {
         for(int j = 30 ; j >= 0 ; j--)
         {
                if((x&(1<<j)) > 0)
                return j;
         }
         return -1;
  }
  static void dfs(int n , LinkedList<Integer> arr[] , int p , int pp[])
  {
         pp[n] = p;
         for(Integer i : arr[n])
         {
                if(i != p)
                {
                       dfs(i,arr,n,pp);
                }
         }
  }
  
  static void dfs2(int n , LinkedList<Integer> arr[] , int p , int w[] , long dp[] , long max[])
  {
         long mx = 0;
         for(Integer i : arr[n])
         {
                if(i != p)
                {
                       dfs2(i,arr,n,w,dp,max);
                       dp[n] += dp[i]+2*w[i];
                       mx = Math.max(mx,w[i]+max[i]);   
                }
         }
         max[n] = mx;
  }
  
 static int getSum( int index , int BITree[])
{
    int sum = 0; // Iniialize result
  
    // index in BITree[] is 1 more than the index in arr[]
   // index = index + 1;
  
    // Traverse ancestors of BITree[index]
    while (index>0)
    {
        // Add current element of BITree to sum
        sum += BITree[index];
  
        // Move index to parent node in getSum View
        index -= index & (-index);
    }
    return sum;
}
  
// Updates a node in Binary Index Tree (BITree) at given index
// in BITree. The given value 'val' is added to BITree[i] and 
// all of its ancestors in tree.
static void updateBIT(int n, int index, int val , int BITree[])
{
    // index in BITree[] is 1 more than the index in arr[]
    //index = index + 1;
  
    // Traverse all ancestors and add 'val'
    while (index <= n)
    {
    // Add 'val' to current node of BI Tree
    BITree[index] += val;
  
    // Update index to that of parent in update View
    index += index & (-index);
    }
}
static int max;
static long inv(int arr[])
{
       int n = arr.length;
       int bit[]  = new int[n+1];
       long ans = 0;
       for(int i = 0 ; i < n; i++)
       {
              updateBIT(n,arr[i],1,bit);
              ans += getSum(n,bit)-getSum(arr[i],bit);
       }
       return ans;
}


static void dfs(int n , int arr[] , LinkedList<Integer> g[] , HashMap<Integer,Integer> map[] , int prime[] , int p)
{
      HashMap<Integer,Integer> mx = new HashMap<Integer,Integer>(); 
       HashMap<Integer,Integer> nextmx = new HashMap<Integer,Integer>(); 
       
       int temp = arr[n];
       for(Integer i : g[n])
       {
              if(i != p)
              {
                     dfs(i,arr,g,map,prime,n);
                     for(Map.Entry entry : map[i].entrySet())
                     {
                            int k = (int)entry.getKey();
                            int v = (int)entry.getValue();
                            
                            if(arr[n]%k == 0)
                            {
                            if(!mx.containsKey(k))
                            mx.put(k,v);
                            
                            else if(!nextmx.containsKey(k))
                            {
                                 if(v >= mx.get(k))
                                 {
                                         nextmx.put(k,mx.get(k));
                                          mx.put(k,v);
                                 }
                                 
                                 else
                                 {
                                        nextmx.put(k,v);
                                 }
                            }
                            
                            
                            else
                            {
                                   if(v >= mx.get(k))
                                   {
                                          nextmx.put(k,mx.get(k));
                                          mx.put(k,v);
                                   }
                                   
                                   else if(v >= nextmx.get(k))
                                   nextmx.put(k,v);
                            }
                     }
              }
       }
}

while(temp > 1)
{
       int x = prime[temp];
       while(temp%x == 0)
       {
              temp = temp/x;
       }
      // int curr = 0;
       if(mx.containsKey(x))
       {
              max = Math.max(max,mx.get(x)+1);
              
              if(nextmx.containsKey(x))
              max = Math.max(max,mx.get(x)+nextmx.get(x)+1);
              
              map[n].put(x,mx.get(x)+1);
       }
       
       else
       {
       map[n].put(x,1);
       max = Math.max(max,1);
       }
}

}
//static int dp[][][];
/*static int merge(int l , int r , int side , int arr[])
{
       if(l == 0 && r == arr.length-1)
       return 0;
       
       if(dp[l][r][side] != -1)
       return dp[l][r][side];
       
       dp[l][r][side] = Integer.MAX_VALUE;
       int col = -1;
       if(side == 0)
       col = arr[l];
       
       else
       col = arr[r];
       
       if(l == 0)
       {
              if(col == arr[r+1])
              dp[l][r][side] = merge(l,r+1,1,arr);
              
              else
              dp[l][r][side] = 1+merge(l,r+1,1,arr);
       }
       
       else if(r == arr.length-1)
       {
          if(col == arr[l-1])
              dp[l][r][side] = merge(l-1,r,0,arr);
              
              else
              dp[l][r][side] = 1+merge(l-1,r,0,arr);    
       }
       
       else
       {
              if(col == arr[l-1])
              dp[l][r][side] = Math.min(dp[l][r][side],merge(l-1,r,0,arr));
              
              else
              dp[l][r][side] = Math.min(dp[l][r][side],1+merge(l-1,r,0,arr));
              
              
              
              if(col == arr[r+1])
              dp[l][r][side] = Math.min(dp[l][r][side],merge(l,r+1,1,arr));
              
              else
              dp[l][r][side] = Math.min(dp[l][r][side],1+merge(l,r+1,1,arr));
       }
       
       return dp[l][r][side];
       

}*/
       public static void main(String []args) throws IOException
       {
              Reader sc = new Reader();
              int w = sc.nextInt();
              int m = sc.nextInt();
              while(m > 0)
              {
                     if(m%w == 0)
                     {
                            m = m/w;
                     }
                     
                     else if((m-1)%w == 0)
                     {
                            m = (m-1)/w;
                     }
                     
                     else if((m+1)%w == 0)
                     {
                            m = (m+1)/w;
                     }
                     
                     else 
                     {
                            break;
                     }
              }
              if(m == 0)
              System.out.println("YES");
              
              else
              System.out.println("NO");
       }
}