import sys
N,M=map(int, sys.stdin.readline().split())
SC=[ map(int, sys.stdin.readline().split()) for _ in range(M) ]
if N==0: N+=1

def judge(s,c,n):
    n=str(n)
    c=str(c)
    l=len(n)
    if l<s: return False
    if l!=N: return False
    if n[s-1]==c:
        return True
    else:
        return False

for n in range(1000):
    for s,c in SC:
        if not judge(s,c,n):
            break
    else:
        print n
        quit()
else:
    print -1