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.lang.*;
import java.io.*;

public class Main
{
	static class InputReader{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
 
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		public String next() {
			return readString();
		}
 
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
	
 
static class OutputWriter {
		private final PrintWriter writer;
 
		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}
 
		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}
 
		public void print(Object...objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}
 
		public void printLine(Object...objects) {
			print(objects);
			writer.println();
		}
 
		public void close() {
			writer.close();
		}
 
		public void flush() {
			writer.flush();
		}
 
		}
 
    static class IOUtils {
 
		public static int[] readIntArray(InputReader in, int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = in.readInt();
			return array;
		}
    }
    static int n;
    static int m;
    static char[] c;
    static OutputWriter out;
    static InputReader in;
    static boolean[] a;
    public static void main (String[] args) throws java.lang.Exception
	{
	    out = new OutputWriter(System.out);
		in = new InputReader(System.in);
        int w = in.readInt();
        m = in.readInt();
        for(int i=0; i<=100; i++){
            if(m==0){out.print("YES"); out.flush(); out.close(); return;}
            else{
                //out.printLine(m+" "+m%w);
                if(m%w>1 && m%w<w-1){out.print("NO"); out.flush(); out.close(); return;}
                else if(m%w==1)m--;
                else if(m%w==w-1)m++;
                m = m/w;
            }
        }
        out.flush();
        out.close();
	}
	
   public static int gcd(int a, int b){
        //b is greater
        if(a>b){int temp = a; a = b; b = temp;}
        if(b%a==0)return a;
        return gcd(b%a, a);
    }
	public static void add(int index, int value, int[] b){
	    while(index < b.length){
	        b[index] += value;
	        index = index + (index & (-index));
	    }
	}
	
	public static int getSum(int index, int [] b){
	    int sum = 0;
	    while(index > 0){
	        sum += b[index];
	        index = index - (index&(-index));
	    }
	    return sum;
	}
	
	public static void printArray(int[] a){
	    for(int i=1; i<a.length; i++)out.print(a[i]+" ");
	    out.printLine("---------");
	}
	
	static class Pair implements Comparable<Pair>{
	    int s;
	    //int d;
	    int len;
	    public Pair(int a, int c){
	        s = a; len = c;
	    }
	    public int compareTo(Pair p){
	        if(this.len > p.len)return 1;
	        else if(this.len < p.len)return -1;
	        return 0;
	    }
	}
}