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 (q[0] == 1 and q[1] == 0):
        print(-1)
        exit()
    elif ans[q[0]-1] == None:
        ans[q[0]-1] = q[1]
    elif ans[q[0]-1] != q[1]:
        print(-1)
        exit()

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