n = int(input())
m = input().strip()
def a(s, b):
    return int(s, b)
def b(c, d):
    e = "0123456789ABCDEF"
    if c == 0:
        return "0"
    f = ""
    while c > 0:
        f = e[c % d] + f
        c = c // d
    return f
def c(s):
    return s[::-1]
g = 0
h = m
while g <= 30:
    if h == c(h):
        print(f"STEP={g}")
        exit()
    g += 1
    i = c(h)
    j = a(h, n)
    k = a(i, n)
    l = j + k
    h = b(l, n)
print("Impossible!")