n,m=map(int, input().split())
l=[]
cnt=0
if m==1:
    s,c=map(int, input().split())
    if s==1 and c==0:
        print('-1')
    elif s!=n:
        print(10**(n-1)+c*(10**(n-s)))
    else:
        print(c*(10**(n-s))
else:
    for i in range(m):
        s,c=map(int, input().split())
        l.append([s,c])
        if s==1 and c==0: #最上位の位が0の時に対する処理
            cnt+=1
    buf=0
    for i in range(m-1):
        for j in range(i+1,m):
            if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:
                buf+=1
    if buf!=0 or cnt!=0:
        print('-1')
    else:
        l.sort()
        ans=l[0][1]*(10**(n-l[0][0]))
        for i in range(1,m):
            if l[i-1][0]==l[i][0]:
                continue
            else:
                ans+=l[i][1]*(10**(n-l[i][0]))
        print(ans)