#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, k;
vector<pair<int, int> > ps;
int dp[N][N][N];
int INF = numeric_limits<int>::max();
int solve(int pt) {
  if (pt > n) return INF;
  memset(dp, 0x7f, sizeof(dp));
  dp[0][0][ps[0].first + 1 < pt] = 0;
  dp[0][1][ps[0].first <= pt] = ps[0].second;
  for (int i = 1; i < n; ++i) {
    int p = ps[i].first;
    int e = ps[i].second;
    for (int j = 0; j <= n; ++j) {
      for (int t = 0; t <= n; ++t) {
        dp[i][j][t + (p + 1 < pt)] =
            min(dp[i][j][t + (p + 1 < pt)], dp[i - 1][j][t]);
        dp[i][j + 1][t + (p <= pt)] =
            min(dp[i][j + 1][t + (p <= pt)], dp[i - 1][j][t] + e);
      }
    }
  }
  int needed = n - k + 1;
  int res = INF;
  for (int i = needed; i <= n; ++i) res = min(res, dp[n - 1][pt][i]);
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> k;
  ps.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> ps[i].first >> ps[i].second;
  }
  if (n + 1 == k) {
    cout << 0 << endl;
    return 0;
  }
  sort(ps.begin(), ps.end());
  reverse(ps.begin(), ps.end());
  int needed = ps[k - 1].first;
  int res = INF;
  for (int i = needed; i < needed + 3; ++i) res = min(res, solve(i));
  if (res != INF)
    cout << res << endl;
  else
    cout << -1 << endl;
  return 0;
}
