N, M = map(int, input().split())
scl = [list(map(int, input().split())) for _ in range(M)]

mincand = 10**(N-1)
maxcand = 10**N-1

for i in range(mincand, maxcand+1):
    if all([str(i)[s-1] == str(c) for s, c in scl]):
        print(i)
        exit()
print(-1)