n,m = map(int,input().split())
s=[0]*m
c=[0]*m
for i in range(m):
    s[i],c[i]=map(int,input().split())
N=[0]*n
t=0

for i in range(m):
    k=s[i]-1
    if k==0 and c[i]==0:
        t+=1
        break
    N[k]=c[i]
    for j in range(m):
        if s[i]==s[j] and c[i]!=c[j]:
            t+=1
            break
a=0
if t>0:
    print(-1)
else:
    for p in range(n):
        a+=int(N[p]*(10**(n-p-1)))
    print(a)
