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