NM = list(map(int, input().split()))

dict = {}

for i in range(NM[1]):
    sc = list(map(int, input().split()))
    if ((sc[0] in dict) and (dict[sc[0]] != sc[1])):
        print(-1)
        exit()
    dict[sc[0]] = sc[1]

keta = 10 ** (NM[0] - 1)
num = 0
check = True
if (1 in dict):
    if (keta == 1 and dict[1] == 0):
        print(-1)
        exit()
    num += dict[1] * keta
    check = False

if (keta == 1):
    if (check):
        print(-1)
        exit()
else:
    keta /= 10
    if (2 in dict):
        if (check and dict[2] == 0):
            print(-1)
            exit()
        num += dict[2] * keta
        check = False

    if (keta == 1):
        if (check):
            print(-1)
            exit()
    else:
        if (3 in dict):
            num += dict[3]
        else:
            if (check):
                print(-1)
                exit()

print(num)