n,m = map(int,input().split())
sc_inputs = [[int(j) for j in input().split()] for i in range(m)]

li = [0]*n
ans=0
for sc in sc_inputs:
    s,c = map(int,sc)
    if li[s-1]!=0:
     if li[s-1]!=c:
        ans=-1
        break
    li[s-1]=c
if li[0]==0:
    ans=-1
if ans!=-1:
    ans=''.join(map(str,li))

print(ans)

