import os

def main():
    list_min1 = []
    list_min2 = []
    list_min3 = []

    n,m = (int(x) for x in input().split())
    input_list = [0] * n
    
    for i in range(m):
        keta,num = (int(x) for x in input().split())
        if keta = 1:
            min_num = min1(num,list_min1)
        elif keta = 2:
            min_num = min2(num,list_min2)
        else:
            min_num = min3(num,list_min2)
            
        input_list[keta - 1] = min_num

    if input_list[0] == 0:
        if len(input_list) == 1:
            print(0)
        else:
            print(-1)
    else:
        print(IntChange(input_list))


def min1(num,list_min):
    list_min.append(num)
    return min(list_min)

def min2(num,list_min):
    list_min.append(num)
    return min(list_min)

def min3(num,list_min):
    list_min.append(num)
    return min(list_min)


def IntChange(int_list):
    num = ""
    str_list = [str(n) for n in int_list]
    for i in str_list:
        num = num + i
    return int(num)


if __name__ == "__main__":
    main()