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