#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int IINF = 1000000000;
const double PI = acos(-1.0);
const long long LINF = 6000000000000000000LL;
const int maxN = 200 * 1000 + 7;
int n, k, E[maxN], P[maxN], CP[maxN], W[maxN];
bool Read() {
  if (scanf("%d%d", &n, &k) == 2) {
    for (int i = 0; i < n; ++i) {
      scanf("%d%d", P + i, E + i);
    }
    return true;
  }
  return false;
}
bool cmp(int i, int j) {
  if (i == n || j == n) {
    if (i == n) {
      if (CP[i] != CP[j]) return CP[i] > CP[j];
      if (W[j]) return true;
      return false;
    } else if (j == n) {
      if (CP[i] != CP[j]) return CP[i] > CP[j];
      if (W[i]) return false;
      return true;
    }
  }
  if (CP[i] != CP[j]) return CP[i] > CP[j];
  return i > j;
}
long long can(int mask) {
  vector<pair<int, int> > v;
  v.reserve(n);
  for (int i = 0; i < n; ++i) {
    v.push_back(make_pair(E[i], P[i]));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i <= n; ++i) {
    CP[i] = 0;
    W[i] = 0;
  }
  long long ans = 0;
  for (int i = 0; i < v.size(); ++i) {
    if (mask & (1 << i)) {
      ans += v[i].first;
      CP[n]++;
      W[i] = 1;
      CP[i] = v[i].second;
    } else {
      CP[i] = v[i].second + 1;
    }
  }
  vector<int> srt;
  for (int i = 0; i < n; ++i) {
    srt.push_back(i);
  }
  srt.push_back(n);
  sort(srt.begin(), srt.end(), cmp);
  for (int i = 0; i < srt.size(); ++i) {
    if (srt[i] == n) {
      if (i + 1 <= k) {
        return ans;
      }
      return LINF;
    }
  }
  return LINF;
}
int main() {
  while (Read()) {
    long long ans = LINF;
    for (int mask = 0; mask < (1 << n); ++mask) {
      ans = min(ans, can(mask));
    }
    if (ans >= LINF)
      printf("-1\n");
    else
      printf(
          "%lld"
          "\n",
          ans);
  }
  return 0;
}
