n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    t = str(i)
    if len(t) != n: continue
    for s, c in sc:
        if str(c) != t[s-1]: break
    else:
        print(i)
        break
else: print(-1)
