n, m = map(int, input().split())
ans = list("000")
x = [list(map(int, input().split())) for i in range(m)]
x = list(map(list, set(map(tuple, x))))
for s, c in x:
    if ans[s-1] == "0":
        ans[s-1] = str(c)
    else:
        print("-1")
        exit()
ans = "".join(ans)

if n == 1:
    ans = int(ans[2:])
    for i in range(10):
        if i == ans:
            print(i)
            exit()
    print(-1) 

if n == 2:
    if ans[1]=="0":
        ans[1]=="1"
    else:
        ans = int(ans[1:])
    for i in range(10, 100):
        if i == ans:
            print(i)
            exit() 
    print(-1)

if n == 3:
    if ans[0]=="0":
        ans[0]=="1"
    else:
        ans = int(ans[0:])
    for i in range(100, 1000):
        if i == ans:
            print(i)
            exit()
    print(-1) 