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]

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

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

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

print(num)