import sys
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

num=[0]*n

for i in range(m):
    if sc[i][0]==0:
        print('-1')
        sys.exit()
    if sc[i][1] in num:
        if sc[i][0]-1!=num.index(sc[i][1]):
            print('-1')
            sys.exit()
    else:
        num.insert(sc[i][0]-1,sc[i][1])

c=0

if num[0]==0:
    print('-1')
    sys.exit()

else:
    for i in range(n):
        c+=num[i]*(10**(n-i-1))
    
print(c)