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

listans = [0] * n
ans = 0

for i in range(m):
    s, c = map(str, input().split())
    if listans[int(s)-1] == 0:
        listans[int(s)-1] = int(c)
    elif listans[int(s)-1] != int(c):
        ans = -1

if listans[0] == 0:
    ans = -1
else :
    if ans == 0:
        ans = int("".join(listans))

print(ans)