import sys b=int(input()) s=input() d=int(s, b) if d