#include <bits/stdc++.h>
using namespace std;
struct WTH {
  int a, b, c, d;
};
bool com(WTH p1, WTH p2) {
  if (p1.a < p2.a)
    return 1;
  else if (p1.a == p2.a && p1.b < p2.b)
    return 1;
  return 0;
}
WTH arr[20], cop[20], me;
int main() {
  int t, k, mini = 9999999;
  cin >> t >> k;
  for (int i = 0; i < t; i++) cin >> arr[i].a >> arr[i].c, arr[i].b = 0;
  for (int i = 0; i < (1 << t); i++) {
    cop[t].a = cop[t].c = cop[t].b = 0, cop[t].d = -1;
    for (int i = 0; i < t; i++)
      cop[i].a = arr[i].a, cop[i].b = 0, cop[i].c = arr[i].c, cop[i].d = 0;
    for (int j = 0; j < t; j++) {
      if (i & (1 << j))
        cop[t].a++, cop[t].c += arr[j].c;
      else
        cop[j].a++, cop[j].b = 1;
    }
    sort(cop, cop + t + 1, com);
    int cc = 1, j = t;
    for (int j = t; j >= 0; j--, cc++)
      if (cop[j].d == -1) break;
    if (cc <= k) mini = min(mini, cop[t + 1 - cc].c);
  }
  if (mini == 9999999) mini = -1;
  cout << mini;
}
