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 = [-1, -1, -1]
elif n == 2:
    ans = [-1, -1]
else:
    n = [-1]
answer = 0
if n != 1 and sc[0][0] != 1:
    answer = -1
elif n != 1 and sc[0][1] == 0:
    answer = -1
else:
    for i in range(m):
        r = sc[i][0] - 1
        if ans[r] > sc[i][1] or ans[r] == -1:
            ans[r] = sc[i][1]
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
    if answer != -1 and ans[0] != 0:
        answer = 0
        for j in range(n):
            answer += ans[j] * 10 ** (n - j - 1)
print(int(answer))