N = input().split(" ")
keta = int(N[0])
jyouken = int(N[1])
ichi = int(-1)
ni = int(-1)
san = int(-1)
unko = int(0)
a = []
for i in range(jyouken):
    a.append(input().split(" "))
    
for i in range(jyouken):
    if int(a[i][0]) == 1:
        if ichi == -1:
            ichi = a[i][1]
        elif ichi == a[i][1]:
            pass
        else:
            unko = 1
    elif int(a[i][0]) == 2:
        if ni == -1:
            ni = a[i][1]
        elif ni == a[i][1]:
            pass
        else:
            unko = 1
    else:
        if san == -1:
            san = a[i][1]
        elif san == a[i][1]:
            pass
        else:
            unko = 1

if unko == 1:
    print(-1)
elif keta == 1:
    print(ichi)
elif keta == 2:
    if int(ichi) == 0:
        print(-1)
    elif int(ni) == -1:
        print(int(ichi) * 10)
    else:
        print(int(ichi) * 10 + int(ni))
else:
    if int(ichi) == 0:
        print(-1)
    elif int(ni) == -1 and int(san) == -1:
        print(int(ichi) * 100)
    elif int(ni) == -1:
        print(int(ichi) * 100 + int(san))
    elif int(san) == -1:
        print(int(ichi) * 100 + int(ni) * 10)
    else:
        s = int(ichi) * 100 + int(ni) * 10 + int(san)
        print(s)


