n, m = map(int, input().split())
A = [1e9] * n
f = True
for _ in range(m):
    s, c = map(int, input().split())
    if A[s - 1] != 1e9:
        if A[s - 1] != c: 
            f = False
    if s - 1 == 0 and c == 0:
        f = False
    A[s - 1] = c

if f:
    ans = ""
    for i in range(len(A)):
        if i == 0 and A[i] == 1e9:
            ans += "1"
        else:
            if A[i] == 1e9:
                ans += "0"
            else:
                ans += str(A[i])
    print(int(ans))
else:
    print(-1)