# coding: utf-8

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

sc_list = []
s_list = []
result = 0
for _ in range(m):
    sc_list.append(list(map(int, input().split())))
sc_list = list(map(list, set(map(tuple, sc_list))))
for sc in sc_list:
    if sc[0] == 1 and sc[1] == 0:
        print(-1)
        exit()
    result += sc[1] * (10 ** (m - sc[0]))
    s_list.append(sc[0])
if len(set(s_list)) != len(sc_list):
    print(-1)
    exit()
if n == 3 and result < 100:
    result += 100
if n == 2 and result >= 100:
    print(-1)
    exit()
if n == 2 and result < 10:
    result += 10
if n == 1 and result >= 10:
    print(-1)
    exit()

print(result)
