n,m = map(int,input().split())
sc = [list(map(int,input().split()))for _ in range(m)]
for i in range(1000):
    ok = True
    x = str(i)
    if len(x) !=n:continue
    for s,c in sc:
        if int(x[s-1]) !=c:
            ok = False
    if ok:
        print(i)
        exit(0)
print(-1)
    
        