n,m=(int(i) for i in input().split())
t=[]
for i in range(n): t += [""]
imposs =  False
for i in range(m):
    a,b=(int(i) for i in input().split())
    a-=1
    b=str(b)
    if a<0 or a>=n or (len(t[a])>0 and t[a]!=b):
        imposs =True
    t[a] = b
if len(t[0])==0:
    imposs = True
if imposs:print(-1)
else:
    for i in range(n):
        if t[i]=="":t[i]="0"
    print(int("".join(t)))