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

res = []
for i in range(10**(N-1), 10**N):
    nm = str(i)
    is_n = True
    for s, c in A:
        if not nm[s-1] == str(c):
            is_n = False
            break
    if is_n:
        res.append(i)

if res:
    print(min(res))
else:
    print(-1)
