import sys

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

cond = list(list(map(int, input().split())) for i in range(m))

num = [0]*n
if len(num) != 1:
    num[0] = 1

for i in range(m):
    digit = cond[i][0] - 1
    a = cond[i][1]
    if num[digit] == 0 or num[digit] == a:
        num[digit] = a
    else:
        print(-1)
        sys.exit()
        
if num[0] == 0 and len(num) != 1:
    print(-1)
    sys.exit()

number = 0
for i in range(n):
    d = n - i - 1
    number += pow(10,d)*num[i]
    
print(number)