#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int o = 0, c = 0, n, x, y, i, m, count = 0;
  cin >> n >> m;
  vector<long long int> v;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back(x - y);
    o += x;
    c += y;
  }
  if (o <= m) {
    cout << 0;
    return 0;
  }
  if (c > m) {
    cout << -1;
    return 0;
  }
  sort(v.begin(), v.end(), greater<long long int>());
  for (i = 0; i < n; i++) {
    o -= v[i];
    count++;
    if (o <= m) break;
  }
  cout << count;
}
