N = input().split(" ")
keta = int(N[0])
jyouken = int(N[1])
ichi = int(-1)
ni = int(-1)
san = int(-1)
unko = int(0)
a = []
if jyouken > 0:
    for i in range(jyouken):
        a.append(input().split(" "))
if jyouken > 0:        
    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:
    if jyouken > 0:
        print(ichi)
    else:
        print(0)
        
elif keta == 2:
    if jyouken == 0:
        print(10)
    elif int(ichi) == 0:
        print(-1)
    elif int(ni) == -1:
        print(int(ichi) * 10)
    else:
        print(int(ichi) * 10 + int(ni))
else:
    if jyouken == 0:
        print(100)
    elif 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)