import sys

N,M = [ int(x) for x in input().split(" ")]
s = [None]*M
c = [None]*M
for i in range(M):
    s[i],c[i] = [ int(x) for x in input().split(" ")] 

a = [None]*N

for i in range(len(s)):
    if(N<s[i]):
        print(-1)
        exit(0)
    if(1==s[i]):
        if(not N==1):
            if(0==c[i]):
                print(-1)
                exit(0)
    if not None==a[s[i]-1]:
        if not a[s[i]-1]==c[i]:
            print(-1)
            exit(0)
    a[s[i]-1]=c[i]

ans = 0
for i in range(len(a)):
    if None==a[0]:
        a[0]=1
    if None==a[i]:
        a[i]=0
    ans+=a[i]*10**(len(a)-i-1)
print(ans)