#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> A(n + 1);
  vector<int> B(n + 1);
  vector<int> D(n + 1);
  ll S = 0;
  for (int i = 1; i <= n; i++) {
    cin >> A[i] >> B[i];
    D[i] = A[i] - B[i];
    S += A[i];
  }
  sort(D.begin(), D.end());
  ll R(0);
  for (int i = n; i >= 1 && S > m; i--) {
    S -= D[i];
    R++;
  }
  if (S <= m) {
    cout << R << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}
