ans=-1
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for k in range(10**n):
    for i in range(m):
        if str(k)[l[i][0]-1]!=str(l[i][1]) or len(str(k))!=n:
            break
    else:
        ans=k
        break
print(ans)