#include <bits/stdc++.h>
using namespace std;
int n, k, t;
int score = 0;
int energy = 0;
int best = 3000001;
int e[15];
int s[15];
bool b[15]{false};
int w[15];
void dfs(int x) {
  if (x == n) {
    t = n + 1;
    for (int i = 0; i < n; i++)
      if (score > s[i] || (score == s[i] && b[i])) t--;
    if (t <= k) best = min(best, energy);
    return;
  }
  if (energy > best) return;
  energy += e[x];
  score++;
  b[x] = true;
  dfs(x + 1);
  energy -= e[x];
  score--;
  b[x] = false;
  s[x]++;
  dfs(x + 1);
  s[x]--;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> s[i] >> e[i];
  dfs(0);
  if (best != 3000001)
    cout << best;
  else
    cout << -1;
  return 0;
}
