n, m = map(int, input().split())
sc = [[int(i) for i in input().split()] for i in range(m)]
sc.sort()
if n == 3:
    ans = [0, 0, 0]
elif n == 2:
    ans = [0, 0]
else:
    n = [0]
answer = 0
if sc[0][0] != 1 or sc[-1][0] > n:
    answer = -1
elif sc[0][1] == 0 and n != 0:
    answer = -1
elif sc[0][1] == 0:
    answer = 0
else:
    for i in range(m):
        r = sc[i][0] - 1
        if ans[r] > sc[i][1] or ans[r] == 0:
            ans[r] = sc[i][1]
    if answer != -1:
        answer = 0
        for j in range(n):
            answer += ans[j] * 10 ** (n - j - 1)
print(int(answer))
