#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 4e18;
const int inf = 2e9;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mask, e[20], p[20];
bool win[20];
long long ans = INF;
int main(void) {
  int i, j, n, k;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; ++i) scanf("%d %d", p + i, e + i);
  for (mask = 0; mask < (1 << n); ++mask) {
    long long cur = 0;
    int point = 0;
    memset(win, 0, sizeof(win));
    for (i = 0; i < n; ++i) {
      if (mask & (1 << i)) cur += e[i], ++point, win[i] = 1;
    }
    int atas = 0;
    for (i = 0; i < n; ++i) {
      if (p[i] + 1 < point) continue;
      if (p[i] <= point && win[i]) continue;
      atas++;
    }
    if (atas < k) ans = min(ans, cur);
  }
  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
}
