# n, m = int(input().split())
n, m = (int(x) for x in input().split())
lst = []
# print(n, m)

for cnt in range(n):
    lst.append(0)


flag = True
for cnt in range(m):
    s, c = (int(x) for x in input().split())
    if(lst[s - 1] != 0):
        flug = False
    else:
        lst[s - 1] = c

num = 0

# print(lst)


if(not flag or lst[0] == 0):
    num = -1

else:
    for cnt in range(n):
        num += lst[cnt] * (10 ** (3 - cnt - 1))


print(num)
