n, m = map(int, input().split())
num = {}
fin = True
for i in range(m):
    s, c = map(int, input().split())
    if s not in num:
        num[s] = c
    elif s in num and num[s] != c:
        fin = False
        break
    else:
        pass

if fin:
    num2 = [0] * n
    for j in num.keys():
        num2[j - 1] = num[j]
    if num2[0] == 0:
        print(-1)
        exit()
    else:
        print(int("".join(map(str, num2))))

else:
    print(-1)
