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

array = [0] * n

for i in range(3):
    if sc[i][0] == 1:
        if array[0] == 0:
            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:
            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:
            array[2] = sc[i][1]
        elif sc[i][1] < array[2]:
            array[2] = sc[i][1]

array = map(str,array)
ans = ''.join(array)

print(int(ans))