n,m=map(int,input().split())
s=[]
c=[]
ans=1000
if m == 0:
    if n == 1:
        ans=0
    elif n==2:
        ans=10
    elif n==3:
        ans=100

for i in range(m):
    s.append(0)
    c.append(0)
    

for i in range(m):
    s[i],c[i]=map(int,input().split())

a=[10,10,10]
for i in range(m):
    s[i] -= 1

for i in range(m):
    if a[s[i]] != 10 and a[s[i]] != c[i]:
        ans = -1
        break
    else:
        a[s[i]] = c[i]

if n==1 and a[2] == 10:
    ans=0
elif a[n-1] == 10:
    a[n-1] = 1
elif a[1] == 10:
    a[1]=0
elif a[2] == 10:
    a[2]=0


if ans == 1000:
    ans =a[0]*100+a[1]*10+a[2]*1

print(ans)