n = int(raw_input())
s = int(raw_input())

if n < s:
    print -1
elif s == 1:
    print n
else:
    ans_list = []
    for i in xrange(n/2, 1, -1):
        tmp_n = n
        total = 0
        while tmp_n / i > 0:
            total += tmp_n % i
            tmp_n /= i
        total += tmp_n

        print i, total
        if total == s:
            ans_list.append(i)

    print ans_list[len(ans_list)-1] if ans_list else -1