n,m=map(int,input().split())
words=[set() for _ in range(n)]
for s,c in [list(map(int,input().split())) for _ in range(m)]:
    words[s-1].add(str(c))

for i in range(n):
    if len(words[i])>1:
        print(-1)
        exit()

for i,j in enumerate(words):
    if len(words[i])==0:
        for k in range(10):
            words[i].add(str(k))

for i in range(10**(n-1),10**n):
    num=list(str(i))
    N=[]
    for j in num:N.append(set(j))
    cnt=0
    for k in range(n):
        if len(words[k]&N[k])==1:cnt +=1
        if cnt==n:
            print(i)
            exit()

print(-1)