n, m = map(int, input().split())
l = [0, 0, 0]
ans = 0
for _ in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        ans = -1
    if l[s - 1] == 0 or l[s - 1] == c:
        l[s - 1] = c
    else:
        ans = -1
if n == 3 and l[0] == 0:
    l[0] = 1
if n == 2 and l[1] == 0:
    l[1] = 1
print(l[0]*100+l[1]*10+l[2] if ans == 0 else ans)
