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 Main implements Runnable {
		
	public void solve() throws IOException {
               /* W = 4;
                * 256 64 16 4 1
                * When M = 64
                * PAN1 => (1)
                * PAN2 = > (2)
                * 
                * THEN PUT M in (1)
                * to weight
                * 256 64 16 4 1
                *     (2)
                * so put 64 in 2 ans done
                * 
                * Eg:= 2
                * 
                * M = 60 put in (1)
                * 256 64 16 4 1
                *     (2)  (1)
                * 
                * done
                * but note according to code
                * when M+1 % W == 0 put the weight in PAN in (1) ie same as M
                * when M-1 % W == 0 put in PAN (2)
                * when M % W == 0 ; don't use that weight
                * other cases NOT POSSIBLE
                * 
                * 
                * Solution 2:
                * try brute force with bits
                */
                
                int W = nextInt();
                int M = nextInt();
                if(W <= 3){
                        out.println("YES");
                        return;
                }
                
                while(M != 0){
                        if(M % W == 0){
                                M /= W; // don't use it
                        }
                        else if((M+1) % W == 0){
                                M = (M+1)/ W; // add on the same plate as M
                        }
                        else if((M-1) % W == 0){
                                M = (M-1) / W; // add on the other plate opposite to M
                        }
                        else{
                                out.println("NO"); //can't weight
                                return;
                        }
                }
                
                
                out.println("YES");
                
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }
        
        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }
        
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}