#include <bits/stdc++.h>
using namespace std;
int p[105], e[105];
int f(int b, int n, int k) {
  int point = 0, cost = 0, lose = 0;
  int m = b;
  while (m != 0) {
    if (m % 2 == 1) point++;
    m /= 2;
  }
  for (int i = 0; i < n; i++) {
    if (b % 2 == 0) {
      if (p[i] + 1 >= point) lose++;
    } else {
      cost += e[i];
      if (point < p[i]) lose++;
    }
    b /= 2;
  }
  if (lose > k - 1)
    return 1e9;
  else
    return cost;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i] >> e[i];
  int ans = 1e9;
  for (int i = 0; i < (1 << n); i++) ans = min(ans, f(i, n, k));
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
