n,m=map(int,input().split())
lst=['0' for i in range(m)]
f=0
for i in range(m):
    a,b=map(int,input().split())
    if(b<0):
        print(-1)
        f=1
        break
    if(lst[a-1]=='0'):
        lst[a-1]=str(b)
    elif(int(lst[a-1])>b):
        lst[a-1]=str(b)
if(f==0):
    if(lst[0]=='0'):
        print(-1)
    else:
        r="".join(lst)
        print(r)