N,M = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(M)]
L = sorted(l)
if M == 0:
    if N == 1:
        ans = 0
    else:
        ans = 10**(N-1)
else:
    if N == 1 and L[0][1] == 0:
        ans = 0
    elif N != 1 and L[0][1] == 0:
        ans = -1
    else:
        for n in range(M-1):
            if (L[n][0] == L[n+1][0]) and (L[n][1] != L[n+1][1]):
                ans = -1
                break
            else:
                s = sorted(list(set(list(map(tuple,L)))))
                m = len(s)
                if s[0][0] != 1:
                    ans = 10**(M-1)
                else:
                    ans = 0
                for n in range(m):
                    ans += s[n][1]*(10**(M-s[n][0]))
print(ans)