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

