import sys

s=[]
c=[]
ans=[]
n,m = map(int, input().split())

for i in range(m):
    a,b = map(int, input().split())
    s.append(a)
    c.append(b)

for i in range(n):
    ans.append(-1)

ans[s[0]-1] = c[0]

for i in range(1,m):
    if (s[i] in s[:i]) and (c[i] != c[s[:i].index(s[i])]):
        print(-1)
        sys.exit()
    else:
        ans[s[i]-1] = c[i]

if n == 3:
    if -1 in ans[:1]:
        print(-1)
    else:
        if(ans[2] == -1):
            print(0)
        else:
            if ans[1] == -1:
                ans[1] = 0
            if ans[2] == -1:
                ans[2] = 0
            print(ans[0]*100+ans[1]*10+ans[2])
elif n==2:
    if -1 == ans[0]:
        print(-1)
    else:
        if(ans[1] == -1):
            print(0)
        else:
            if ans[1] == -1:
                ans[1] = 0
            print(ans[0]*10+ans[1])
else:
    if ans[0] == -1:
        print(0)
    else:
        print(ans[0])

