n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
ans = ''.join(ans).replace('t', str(0))
print(ans)
ans = int(ans)
l = str(ans)
print(l)
if len(l) != n:
    print(-1)
else:
    print(ans)