# Code for C - Guess The Number
# Use input() to fetch data from STDIN
import sys
[n, m] = [int(x) for x in input().split()]
s = []
c = []

for i in range(m):
    [x, y] = [int(x) for x in input().split()]
    s.append(x)
    c.append(y)

for x in range(1, 1000):
    a = str(x)
    if len(a) != n:
        continue

    test = all([a[i - 1] == str(j) for i, j in zip(s, c)])
    if test:
        print(x)
        sys.exit()

print("-1")
