import sys
#n,m
n,m=(int(x) for x in input().split())

keta = [99,99,99]

for i in range(m):
    s,c=(int(x) for x in input().split())
    if keta[s-1] <= 9 and keta[s-1] != c:
        print(-1)
        sys.exit()
    else:
        keta[s-1] = c

if n == 1 and keta[0] == 0 :
    print(0)
    sys.exit()

if n == 2 and (keta[0] == 0 or keta[0] == 99) and keta[1] == 0:
    print(0)
    sys.exit()

if n == 3 and (keta[0] == 0 or keta[0] == 99) and (keta[1] == 0 or keta[1] == 99) and keta[2] == 0:
    print(0)
    sys.exit()

if n == 2 and keta[0] == 0 :
    print(-1)
    sys.exit()

if n == 3 and keta[0] == 0 :
    print(-1)
    sys.exit()

if n == 3 and keta[0] == 99 and keta[1] == 0 :
    print(-1)
    sys.exit()

kakikomi_flg = "N"
for i in range(n):
    if keta[i] == 99 or keta[i] == 0 :
        if kakikomi_flg == "Y":
            print(0, end="")
    else:
        print(keta[i], end="")
        kakikomi_flg = "Y"
