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-1),10**n):
    for i in range(m):
        if str(k)[l[i][0]-1]!=str(l[i][1]):
            break
    else: 
        ans=k
        print(ans) 
        break
if ans==-1: print(-1)
if n==1 and l[0][0]==0: print(0)