import collections

N,M=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(M)]
flag=1
l=[[i+1,-1] for i in range(N)]
ns=""

for i in range(M):
    #print(l)
    if l[s[i][0]-1][1]==-1:
        l[s[i][0]-1][1]=s[i][1]
    else:
        if not(l[s[i][0]-1][1]==s[i][1]):
            flag=0
#print(l)
if (not(len(l)==1)and(l[0][1]==0))or(l[0][1]==-1):
    flag=0
if flag==1:
    for i in range(N):
        if l[i][1]==-1:
            if i==0:
                l[i][1]=1
            else:
                l[i][1]=0
        ns="".join((ns,str(l[i][1])))
    print(ns)
else:
    print("-1")

