import sys
n,m=map(int,input().split())
number=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    if number[s-1]==0:
        number[s-1]=c
    elif number[s-1]==c:
        continue
    else:
        print(-1)
        sys.exit()
if number.count(0)<n and number[0]==0:
    number[0]=1
answer=''
for i in range(len(number)):
    answer+=str(number[i])
if answer=='0'*n and n!=1:
    answer=-1
print(int(answer))