import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class ReadingBooks {
    static class Book {
        int t;
        int a;
        int b;

        Book(int t, int a, int b) {
            this.t = t;
            this.a = a;
            this.b = b;
        }
    }

    static class SortbyTime implements Comparator<Book> {
        public int compare(Book a, Book b) {
            return a.t - b.t;
        }
    }static class SortbyA implements Comparator<Book> {
        public int compare(Book a, Book b) {
            return a.a - b.a;
        }
    }static class SortbyB implements Comparator<Book> {
        public int compare(Book a, Book b) {
            return a.b - b.b;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        Book[] books = new Book[n];
        for (int i = 0; i < n; i++) {
            int t = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            books[i] = new Book(t, a, b);

        }
        Arrays.sort(books, new SortbyB());
        Arrays.sort(books, new SortbyA());
        Arrays.sort(books, new SortbyTime());
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int tt = 0;
            int at = 0;
            int bt = 0;
            for (int j = i; j < n; j++) {
                if (!(books[j].a == 0 && books[j].b == 0)) {
                    if (at >= k && books[j].b != 0) {
                        bt += books[j].b;
                        tt += books[j].t;
                    } else if (bt >= k && books[j].a != 0) {
                        at += books[j].a;
                        tt += books[j].t;
                    }else{
                        at += books[j].a;
                        bt += books[j].b;
                        tt += books[j].t;
                    }

                    if (at >= k && bt >= k && min > tt) {
                        min = tt;
                    }
                }
            }
        }
        if(min !=Integer.MAX_VALUE)
        System.out.println(min);
        else
            System.out.println("-1");

    }


}
