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

a = [input().split() for i in range(m)]

s = []
c = []

for i in range(m):
    s.append(a[i][0])
    c.append(a[i][1])

S = [int(i) for i in s]
C = [int(i) for i in c]

x = 0
z = 0

for i in range(m):
    x += C[i] * (10 ** (n-S[i]))
    for k in range(m):
        if n >= 2 and S[i] == 1 and C[i] == 0:
            z += 1
            break
        if S[i] == S[k] and C[i] != C[k]:
            z += 1
            break
        if S[i] == S[k] and C[i] == C[k] and i > k:
            x -= C[i] * (10 ** (n-S[i]))
            break

if z == 0:
    if ('1' in S) or m == 0:
        print(x)
    else:
        print(x+10**(n-1))

else:
    print('-1')