n,m=[int(i) for i in input().split(" ")]

s,c=[],[]

for i in range(m):
    x,y=[int(i) for i in input().split(" ")]
    if x==1 and y==0 and n!=1:
        print(-1)
        exit(0)
    if not x in s:
        s.append(x)
        c.append(y)
    else:
        if c[s.index(x)]!=y:
            print(-1)
            exit(0)

sum=0
for i in range(len(s)):
    sum+=c[i]*(10**(n-s[i]))

print(sum)
