import sys
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(0, 1000):
    ok = True
    for si, ci in sc:
        if (i//10**(N-si)) % 10 != ci:
            ok = False
    if ok:
        print(i)
        sys.exit()
else:
    print(-1)
