#include <bits/stdc++.h>
int arr[100][2], k, n, min = 20000000, a[100];
void solve(int i, int point, int kisi) {
  int j = 0, sayac = 0;
  if (kisi == n) {
    for (j = 0; j < n; j++)
      for (j = 0; j < n; j++) {
        if ((arr[j][0] == point && !a[j]) || (arr[j][0] > point)) {
          sayac++;
        }
      }
    if (sayac + 1 <= k) {
      if (i < min) min = i;
    }
    return;
  }
  a[kisi] = 1;
  solve(i + arr[kisi][1], point + 1, kisi + 1);
  a[kisi] = 0;
  arr[kisi][0]++;
  solve(i, point, kisi + 1);
  arr[kisi][0]--;
  return;
}
int main() {
  int x, y, i, j;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &arr[i][0], &arr[i][1]);
  }
  solve(0, 0, 0);
  if (min != 20000000)
    printf("%d", min);
  else
    printf("-1");
  return 0;
}
