Vanya has a scales for weighing loads and weights of masses *w*<sup class="upper-index">0</sup>, *w*<sup class="upper-index">1</sup>, *w*<sup class="upper-index">2</sup>, ..., *w*<sup class="upper-index">100</sup> 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.
The first line contains two integers *w*, *m* (2 ≤ *w* ≤ 10<sup class="upper-index">9</sup>, 1 ≤ *m* ≤ 10<sup class="upper-index">9</sup>) — the number defining the masses of the weights and the mass of the item.
from sys import stdout
from sys import stdin
def get():
    return stdin.readline().strip()
def getf():
    return [int(i) for i in get().split()]
def put(a, end = "\n"):
    stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
    stdout.write(sep.join([str(i) for i in a]) + end)
def putff(a, sep = " ", end = "\n"):
    [putf(i, sep, end) for i in a]

#from math import ceil, gcd, factorial as fac
#from collections import defaultdict as dd
#from bisect import insort, bisect_left as bl, bisect_right as br

def transf(a, w):
    ans = []
    while(a > 0):
        ans.append(a % w)
        a //= w
    return ans[ :: -1]

def main():
    w, m = getf()
    m_w = transf(m, w)
    ans = []
    for i in m_w:
        if(i not in [0, 1, w - 1]):
            put("NO")
            return 0
    put("YES")
main()
