n, m = map(int, input().split())
sc = [input().split() for _ in range(m)]
for i in range(10**(n - 1) if n > 1 else 0, 10**n):
    a = str(i)
    for s, c in sc:
        if a[int(s) - 1] != c:
            break
    else:
        print(i)
        break
else:
    print(-1)