N,M=map(int, input().split())
SC=[tuple(map(int, input().split())) for _ in range(M)]
for i in range(1000):
    x=str(i)
    if len(x)!=N: continue
    for s,c in SC:
        if s-1>=len(x) or int(x[s-1])!=c:
            break
    else:
        print(i)
        break
else:
    print(-1)