import re
n,m=map(int,input().split())
words=["."]*n
for s,c in [list(map(int,input().split())) for _ in range(m)]:
    if words[s-1]=="." or words[s-1]==str(c):
        words[s-1]=str(c)
    else:
        print(-1)
        exit()

for i in range(10**(n-1),10**n):
    num=str(i)
    result=re.fullmatch(r"".join(words),num)
    if result is not None:
        print(i)
        exit()

print(-1)