n, m = map(int, input().split())

ans = [None] * 3

def solve():
    global ans
    for _ in range(m):
        s, c = map(int, input().split())
        if s == 1 and c == 0 and n > 1:
            return(-1)
        if ans[s-1] is None:
            ans[s-1] = c
        elif ans[s-1] != c: 
            return(-1)

    ans = [x or 0 for x in ans]
    ans = list(map(str, ans))
    return int(''.join(ans))
print(solve())