#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
const long long INF = (1e18) + 7;
int tests, current_case;
int n, k, p[N], e[N];
long long ans;
void message(int current_case) {
  fprintf(stderr, "Case %d solved!\n", current_case);
}
void check(int pts) {
  int t1 = 0, t2 = 0, t3 = 0, i, place, gain = 0;
  long long res = 0;
  multiset<int> s;
  for (i = 1; i <= n; i++) {
    if (p[i] == pts - 1)
      ++t3;
    else if (p[i] == pts)
      ++t2;
    else if (p[i] > pts)
      ++t1;
  }
  if (t1 >= k) return;
  place = k - t1;
  for (i = 1; i <= n; i++) {
    if (p[i] == pts || p[i] == pts - 1) s.insert(e[i]);
  }
  while ((int)(s.size()) > k - t1 - 1)
    res += *s.begin(), ++gain, s.erase(s.begin());
  for (i = 1; i <= n; i++)
    if (!(p[i] == pts || p[i] == pts - 1)) s.insert(e[i]);
  while (!s.empty() && gain < pts)
    ++gain, res += *s.begin(), s.erase(s.begin());
  if (gain != pts) return;
  ans = min(ans, res);
}
int main() {
  int i;
  tests = 1;
  for (current_case = 1; current_case <= tests; current_case++) {
    scanf("%d %d", &n, &k);
    for (i = 1; i <= n; i++) {
      scanf("%d %d", &p[i], &e[i]);
    }
    ans = INF;
    for (i = 0; i <= n; i++) {
      check(i);
    }
    if (ans == INF) {
      printf("-1\n");
    } else {
      printf("%lld\n", ans);
    }
  MESSAGE:
    message(current_case);
  }
  return 0;
}
