#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 * 1000 + 85 - 69;
int order[maxn], p[maxn], e[maxn];
int mask, n, k;
bool cmp(int i, int j) {
  if (p[i] != p[j]) return p[i] > p[j];
  if (i != n and j != n) return true;
  if (i == n) return (mask >> j) & 1;
  return !((mask >> i) & 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> e[i];
    order[i] = i;
  }
  order[n] = n;
  long long int ans = 1000LL * 1000 * 1000;
  ans *= ans;
  for (mask = 0; mask < (1 << n); mask++) {
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      if ((mask >> i) & 1)
        sum += e[i];
      else
        p[i]++;
    }
    p[n] = __builtin_popcount(mask);
    sort(order, order + n + 1, cmp);
    for (int i = 0; i < k; i++)
      if (order[i] == n) ((ans) = min((ans), (sum)));
    for (int i = 0; i < n; i++)
      if (!((mask >> i) & 1)) p[i]--;
  }
  cout << (ans == 1e18 ? -1 : ans) << endl;
  return 0;
}
