#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, a[100002], i, p = 0, q = 0, x, y, k = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    p = p + x;
    q = q + y;
    a[i] = x - y;
  }
  if (q > m)
    cout << -1;
  else {
    sort(a, a + n);
    int h = n - 1;
    while (1) {
      if (p <= m) {
        cout << k;
        break;
      } else {
        p = p - a[h];
        h--;
      }
      k++;
    }
  }
}
