#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> diff(n);
  int a, b;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    sum += a;
    diff[i] = b - a;
  }
  sort(diff.begin(), diff.end());
  assert(diff.size() == n);
  int ans = 0;
  while (sum > m && ans < n) {
    sum += diff[ans++];
  }
  if (sum > m) {
    cout << -1;
    exit(0);
  }
  cout << ans;
  return 0;
}
