from collections import defaultdict

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

sc = [list(map(int, input().split())) for _ in range(m)]

sc.sort()

flag = True

num = {}

for x in sc:
    if x[0] == 1 and x[1] == 0:
        flag = False
        break
    
    if num.get(x[0]) != None and num[x[0]] != x[1]:
        flag = False
        break
    else:
        num[x[0]] = x[1]


a = -1


if flag:
    a = 0
    for k, v in num.items():
        a += v * (10**(n-k))


print(a)
   