n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]

ans = [0, 0, 0]
for q in p:
    ans[q[0]-1] = q[1]

if ans[0] == 0:
    print(-1)
else:
    print("".join(map(str, ans)))
