n,m=map(int,input().split())
ans=[0]*n
buf=0
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]==0:
        ans[s-1]+=c
    elif ans[s-1]!=0 and c!=ans[s-1]:
        buf+=1
if buf==0 and ans[0]!=0:
    anstr=[str(num) for num in ans]
    print(''.join(anstr))
elif buf==0 and ans[0]==0:
    print(-1)
else:
    print(-1)