N, M =map(int, input().split())
sc=[list(map(int, input().split())) for _ in range(M)]
sc.sort(key=lambda x:x[0])

ans=0
if M>N:
    ans=-1
for i in range(M):
    s1, c1 = sc[i]
    if s1>N:
        ans=-1
        break
    for j in range(i+1, M):
        s2, c2 = sc[j]
        if s1==s2 and c1!=c2:
            ans=-1
            break
if len(sc)!=1 and sc[0][0]==1 and sc[0][1]==0:
    ans=-1

if ans!=-1:
    ans_={1:1, 2:0, 3:0}
    for i in range(M):
        s, c = sc[i]
        ans_[s]=c
    for i in range(1, N+1):
        ans=ans*10+ans_[i]

print(ans)