n,m=(int(x) for x in input().split())
k=m+1
s=[0]*k
c=[0]*k
answer=0
for i in range(m):
    s[i+1],c[i+1]=(int(x) for x in input().split())


a=[-1]*10

for i in range(m):
    if a[s[i+1]]==-1:
        a[s[i+1]]=c[i+1]
    elif not a[s[i+1]]==c[i+1]:
        answer=-1
if a[1]==0:
    answer=-1

for i in range(10):
    if a[i]==-1:
        a[i]=0

if answer==0:
    for i in range(n):
        d=n-i-1
        answer+=10**d*a[i+1]
print(answer)