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

for i in range(1000):
    stri = str(i)
    if len(stri) != N:
        continue
    for s, c in sc:
        if stri[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print(-1)