#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  long long t = n;
  for (long long i = 0; i < n; i++) {
    long long ma, mi;
    cin >> ma >> mi;
    a[i] = ma - mi;
    m -= mi;
  }
  sort(a, a + n);
  if (m > 0) {
    for (long long i = 0; i < n; i++) {
      if (a[i] <= m) {
        t--;
        m -= a[i];
      } else {
        break;
      }
    }
    cout << t;
  } else if (m == 0) {
    cout << t;
  } else {
    cout << "-1";
  }
  return 0;
}
