n,m=map(int,input().split())
keep=1
re_ans=""
ans=[0]*n


for i in range(m):
    s=list(map(int,input().split()))
    if ans[s[0]-1]==0:
        ans[s[0]-1]=s[1]
    elif ans[s[0]-1]==s[1]:
        keep*=1
    else:
        keep*=0

for i in ans:
    re_ans+=str(i)


if re_ans[0]=="0":
    keep*=0

print([-1,re_ans][keep])
