#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Node {
  int a, b;
  friend bool operator<(const Node x, const Node y) {
    return x.a - x.b > y.a - y.b;
  }
} c[N];
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long sum = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &c[i].a, &c[i].b);
    sum += min(c[i].a, c[i].b);
    cnt += c[i].a;
  }
  if (sum > m) {
    puts("-1");
    return;
  }
  sort(c + 1, c + 1 + n);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i].a <= c[i].b) continue;
    if (cnt <= m) break;
    cnt -= 1LL * (c[i].a - c[i].b);
    res++;
  }
  printf("%d\n", res);
}
int main() {
  solve();
  return 0;
}
