#include <bits/stdc++.h>
using namespace std;
long long a[100001], b[100001];
long long d[100001] = {};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  long long sum = 0;
  long long sum2 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    d[i] = a[i] - b[i];
    sum += b[i];
    sum2 += a[i];
  }
  long long diff = sum2 - m;
  if (sum > m) {
    cout << -1 << endl;
    return 0;
  }
  sort(d + 1, d + n + 1, greater<long long>());
  for (int i = 1; i <= n + 1; i++) {
    if (diff <= 0) {
      cout << i - 1 << endl;
      return 0;
    }
    diff -= d[i];
  }
  return 0;
}
