n,m=map(int,input().split())
l=[0]*(n+1)
flag=True
for _ in range(m):
    s,c=map(int,input().split())
    if l[s]==0 or l[s]==c:
        l[s]=c
        
    else:
        flag=False
        print(-1)
        break

if flag==True:
    k=0
    for i in range(1,n+1):
        k+=l[i]*10**(n-i)
    if l[1]==0:
        print(k+10**(n-1))
    else:
        print(k)