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

ans = [None, None, None]
for q in p:
    if ans[q[0]-1] == None or ans[q[0]-1] == q[1]:
        ans[q[0]-1] = q[1]
    else:
        print(-1)
        exit()

if ans[0] == 0:
    print(-1)
else:
    ans = list(map(lambda x: 0 if x == None else x, ans))
    print(ans[0]*100+ans[1]*10+ans[2])
