n,m=map(int,input().split())
l=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:print(-1);exit()
if l[0]==0 and n>=2:print(-1);exit()
if l[0]==-1 and n==1:print(0);exit()
for i in range(m):
    if l[i]==-1:
        l[i]="0"
    else:l[i]=str(l[i])
print("".join(l))