n, m = map(int,input().split())

a = [""]*3
rep = []
ans = 0

for i in range(m):
    s,c = input().split()
    if s in rep:
        if c != a[int(s)-1]:
            ans = -1
    rep.append(s)
    a[int(s)-1] = c

if ans == -1:
    print(ans)
else:
    if a[0] == "":
        if a[1] == "":
            print(int(a[2]))
        elif a[2]=="":
            a[2]="0"
            print("".join(a))
    else:
        if a[1] == "":
            print(0)
        elif a[2]=="":
            a[2]="0"
            print("".join(a))
            