n, m = map(int, input().split())
ans = {}

for k in range(1,n+1):
    ans[k] = "x"


for i in range(m):
    s, c = map(int, input().split())
    if ans[s] == "x":
        ans[s] = c
    elif ans[s] != c:
        print(-1)
        exit()

if n != 1 and ans[1] == 0:
    print(-1)
    exit()

if n == 1:
    if ans[1] != "x":
        print(ans[1])
        exit()
    else:
        print(0)
        exit()

if n == 2:
    num = ans[1] * 10
    if ans[2] != "x":
        print(num + int(ans[2]))
        exit()
    else:
        print(num)
        exit()

if n == 3:
    num = ans[1] * 100
    if ans[2] != "x":
        num += ans[2] * 10
    if ans[3] != "x":
        num += ans[3]
    print(num)
    exit()