n, m = map(int, input().split())
# n: ketasuu
# m: num of list
data = [[0] * 2] * m
for i in range(m):
    a, b = map(int, input().split())
    # data[i][0], data[i][1] = a, b  >>>間違い
    data[i] = a, b
dataSort = sorted(data)
start = dataSort[0][0]
strVal = dataSort[0][1]

aList = [0, 0, 0]
flag = True
for i in range(m):
    tar = dataSort[i][0]
    tarVal = dataSort[i][1]

    if (tar == 1 and tarVal == 0):
        # print('-1')
        ans = -1
        flag = False
        break
    if (tar == start):
        if (tarVal != strVal):
            ans = -1
            flag = False
            break

    else:
        start = tar
        strVal = tarVal

    aList[tar - 1] = tarVal


if (flag == True):
    ans = str(aList[0]) + str(aList[1]) + str(aList[2])

print(ans)
