import sys

N, M = map(int, input().split())

hantei = 0
ctmp = []
for i in range(N):
    ctmp.append(-1)

for i in range(M):
    s, c = map(int, input().split())
    
    if ctmp[s - 1] == -1 or ctmp[s - 1] == c:
        ctmp[s - 1] = c
    else:
        hantei = 1

if ctmp[0] == 0:
    hantei = 1
result = 0
tmp = N - 1

if hantei == 1:
    if N == 1:
        print('0')
    else:
        print('-1')
        sys.exit(0)
for i in range(N):
    if ctmp[i] != -1:
        result += ctmp[i] * (10 ** tmp)
    else:
        if i == 0:
            result += 10 ** tmp
        else:
            result += 0
    tmp -= 1
print(result)