a,b=map(int,input().split())
ans=True
List=[]
for i in range(a):
    List+=[10]
lst=[list(map(int,input().split())) for i in range(b)]
for i in range(b):
    if List[lst[i][0]-1]==10:
        List[lst[i][0]-1]=lst[i][1]
    elif List[lst[i][0]-1]==lst[i][1]:
        continue
    else:
        ans=False
        break
if ans:
    for i in range(a):
        if List[i]==10:
            List[i]=0
    if List[0]==0 and len(List)!=1:
        print(-1)
    else:
        print(*List,sep="")
else:
    print(-1)
