n, m = map(int,input().split())
SC = {}
num = ["0"]*n
for _ in range(m):
    s, c = map(int,input().split())
    num[s-1] = str(c)
    if s in SC and SC[s] != c:
        print(-1)
        exit()
    if c == 0 and s == n:
        print(0)
        exit()
    SC[s] = c

if num[0] == "0"and num[1] == "0":
    print(-1)
    exit()

print("".join(num))
