from operator import itemgetter
n,m = map(int,input().split())
t = [list(map(int,input().split())) for _ in range(m)]
t.sort(key=itemgetter(0))
c = [i[1] for i in t ]
s = [i[0] for i in t]
# print(c)
x = 0
ans = "aaa"
ans = list(ans)
for i in range(3):
    for j in range(len(s)):
        if i==s[j]-1 :
            if str(c[j])!=ans[i] and ans[i]=="a":
                ans[i]=str(c[j])
            elif  str(c[j])!=ans[i] and ans[i]!="a":
                x =1

if x==1:
    print(-1)
else:
    for i in range(3):
        if ans[i]=="a":
            ans[i]="0"
    ans = int("".join(ans))
    if n!=len(str(ans)):
        print(-1)
    else:
        print(ans)