n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

array = [-1] * n

for i in range(m):
    if sc[i][0] == 1:
        if array[0] == 0 or array[0] == -1:
            array[0] = sc[i][1]
        elif sc[i][1] < array[0]:
            array[0] = sc[i][1]
    elif sc[i][0] == 2:
        if array[1] == 0 or array[1] == -1:
            array[1] = sc[i][1]
        elif sc[i][1] < array[1]:
            array[1] = sc[i][1]
    elif sc[i][0] == 3:
        if array[2] == 0 or array[2] == -1:
            array[2] = sc[i][1]
        elif sc[i][1] < array[2]:
            array[2] = sc[i][1]

if n == 2:
    if array[0] == -1 and array[1] == 0:
        print("10")
        exit()
    elif array[1] == -1:
        array[1] = 0
elif n == 1:
    array[0] == -1
    array[0] = 0
elif n == 3:
    if array[2] == -1:
        array[2] = 0
    if array[1] == -1:
        array[1] = 0
    if array[0] == -1 or array[0] == 0:
        print("-1")
        exit()
    
array = map(str,array)
ans = ''.join(array)

print(int(ans))