n,m=map(int,input().split())
s=[]
c=[]
for i in range(m):
    p,q=map(int,input().split())
    s.append(p-1)
    c.append(q)

ans=1000
for i in range(max(0,10**(n-1)),(10**n)):
    tmp=str(i)
    flag=True
    for j in range(m):
        if int(tmp[s[j]])!=c[j]:
            flag=False
    if flag:
        ans=min(ans,i)

if ans==1000:
    print(-1)
else:
    print(ans)