N,M=map(int,input().split())
sc=[]
for _ in range(M):
    sc.append(list(map(int,input().split())))
sc.sort()
out=False
for i in range(0,M):
    for j in range(0,M):
        if i==j:
            continue
        else:
            if sc[i][0]==sc[j][0] and sc[i][1]!=sc[j][1]:
                out=True
    if N!=1 and sc[i]==[1,0]:
        out=True
if out:
    print(-1)
else:
    digit=[-1]*N
    for i in range(0,M):
        digit[sc[i][0]-1]=sc[i][1]
    for i in range(0,N):
        if digit[i]==-1:
            digit[i]=0
        print(digit[i],end="")