N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1 = [int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
def guess(N,s,c):
    A = [0 for i in range(N)]
    A[0] = 1
    for i in range(0,len(s)):
        if A[s[i]-1] == 0 or A[s[i]-1] == c[i]:
            A[s[i]-1] = c[i]
        else:
            return -1
    if A[0] == 0 and N != 1:
        return -1
    else:
        t = 0
        for i in range(0,N):
            t = t + A[i] * (10 ** (N-i-1))
        return t
print(guess(N,s,c))