#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  long long int sum_c = 0, sum_uc = 0;
  cin >> n >> m;
  int diff[n];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    diff[i] = a - b;
    sum_c += b;
    sum_uc += a;
  }
  if (sum_c > m)
    cout << "-1" << endl;
  else {
    sort(diff, diff + n);
    int count = 0;
    int counter = n - 1;
    while (sum_uc > m) {
      sum_uc -= diff[counter];
      count++;
      counter--;
    }
    cout << count << endl;
  }
  return 0;
}
