#include <bits/stdc++.h>
using namespace std;
const int maxN = 1256;
const int inf = int(1e9);
int a[20], p[20];
int n, k, res, r, w;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> a[i];
  }
  int ans = inf;
  int N = (1 << n);
  for (int m = 0; m < N; m++) {
    res = r = w = 0;
    for (int i = 0; i < n; i++)
      if (m & (1 << i)) {
        res += a[i];
        w++;
      }
    for (int i = 0; i < n; i++) {
      if (m & (1 << i)) {
        if (p[i] > w) r++;
      } else if (p[i] + 1 >= w)
        r++;
    }
    if (r < k) ans = min(ans, res);
  }
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
