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 num[sc[i][0]-1]!=0 and num[sc[i][0]-1]!=sc[i][1]:
            print('-1')
            sys.exit()
    else:
        num[sc[i][0]-1]=sc[i][1]

c=0

if sum(num)!=0 and num[0]==0:
    print('-1')
    sys.exit()
    
if num[0]==0:
    num.insert(0,1)
    for i in range(n):
        c+=num[i]*(10**(n-i-1))

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