N,M=map(int,input().split())
ans=[0]*(N+1)
for i in range(M):
    s,c=map(int,input().split())
    if ans[s]==0 or ans[s]==c :
        ans[s]=c
    else:
        print('-1')
        exit()
if N>1 and ans[1]==0:
    print('-1')
    exit()
else:
    pass
# FA=ans[1:]
# FA=''.join(FA)
FA=0
for j in range(len(ans)-1):
    FA+=10**j *ans[(-1)*(j+1)]
print(FA)