n,m=map(int,input().split())
l=[0 for i in range(0,3)]

flag=0
y=n
if n<m:
    y=m
for j in range(0,y):
    s,c=map(int,input().split())
    if l[s-1]==0:
        l[s-1]=c
    else:
        if l[s-1]!=c:
            flag=1
            break
    if s==1 and c==0:
        flag=1
        break

if flag==1:
    print(-1)
else:
    for k in range(0,3):
        print(l[k],end="")
