#include <bits/stdc++.h>
using namespace std;
int arr[200005][3];
unordered_map<int, unordered_map<int, unordered_map<int, int> > > memo;
int n, k;
int solve(int book, long long time, int alice, int bob, long long& answer) {
  if (alice >= k && bob >= k) {
    answer = min(answer, time);
    return time;
  }
  if (book >= n || time >= answer) {
    return 1000000000;
  }
  if (memo[book][alice][bob]) {
    return memo[book][alice][bob];
  }
  int take = solve(book + 1, time + arr[book][0], alice + arr[book][1],
                   bob + arr[book][2], answer);
  int leave = solve(book + 1, time, alice, bob, answer);
  return memo[book][alice][bob] = min(leave, take);
}
int main() {
  ios::sync_with_stdio(false);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
  long long answer = 1000000000;
  solve(0, 0, 0, 0, answer);
  if (answer == 1000000000)
    cout << -1 << endl;
  else
    cout << answer << endl;
  return 0;
}
