n,m=map(int, input().split())
l=[]
cnt=0
for i in range(m):
    s,c=map(int, input().split())
    l.append([s,c])
    if s==1 and c==0: #最上位の位が1の時に対する処理
        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**(3-l[0][0]))
    for i in range(1,m):
        if l[i-1][0]==l[i][0]:
            continue
        else:
            ans+=l[i][1]*(10**(3-l[i][0]))
    print(ans)