n,m = map(int, input().split( ))
dic = {}
for i in range(m):
    si,ci = map(int, input().split( ))
    if si in dic:
        if ci!=dic[si]:
            print(-1)
            exit()
    else:
        dic[si]=ci
    if si>n:
        print(-1)
        exit()
if n>1 and 1 in dic:
    if dic[1]==0:
        print(-1)
        exit()
ans = 0
for i in range(1,n+1):
    ans*=10
    if i in dic:
        ans+=dic[i]
print(ans)
