def main():
    n,k=map(int, input().split())
    bs=[]
    l=0
    al, bb=0
    for i in range(n):
        t,a,b=map(int, input().split())
        if a or b:
            bs.append(t)
            if 
    
    if al<k or bb<k:
        print(-1)



if __name__ == '__main__':
    t=1
    for _ in range(t):
        main()

def main():
    n,k=map(int, input().split())
    bs=[]
    l=0
    al, bb=0
    for i in range(n):
        t,a,b=map(int, input().split())
        if a or b:
            bs.append(t)
            if 
    
    if al<k or bb<k:
        print(-1)



if __name__ == '__main__':
    t=1
    for _ in range(t):
        main()
