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