#include <bits/stdc++.h>
using namespace std;
int p[20];
long long e[20];
int n, k;
bool can = false;
long long f(int msk) {
  long long tmp = 0;
  int rnk = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if ((1 << i) & msk) {
      v.push_back(p[i]);
      tmp += e[i];
      rnk++;
    } else {
      v.push_back(p[i] + 1);
    }
  }
  int tt = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > rnk) tt++;
    if (v[i] == rnk && !((1 << i) & msk)) tt++;
  }
  if (tt >= k)
    can = false;
  else
    can = true;
  return tmp;
}
int main() {
  cin >> n >> k;
  long long ans = 1e9;
  int g = 0;
  for (int i = 0; i < n; i++) cin >> p[i] >> e[i];
  for (int i = 0; i < (1 << n); i++) {
    long long tmp = f(i);
    if (can) {
      g++;
      ans = min(ans, tmp);
    }
  }
  if (g)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
