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
    elif l[s-1] == 0 or l[s-1] == c:
        l[s-1] = c
    else:
        ans = -1
print(l[0]*100+l[1]*10+l[2] if ans == 0 else ans)
