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

rl = [-1]*(N+1)

for s, c in sc:
    if rl[s] == -1 or rl[s] == c:
        rl[s] = c
    else:
        print(-1)
        exit()
    if s == 1 and c == 0:
        print(-1)
        exit()

ans = ""
for nd in range(1, N+1):
    c = rl[nd]
    if c == -1:
        if nd == 1: c = 1
        else: c = 0
    ans += str(c)
if (int(ans) == 0):
    if ans !="0":
        print(-1)
        exit()

print(ans)