#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
void print(T t) {
  for (auto& it : t) cout << it << " ";
}
inline long long powerexp(long long a, long long b, long long m) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % m;
    a = a * a % m, b >>= 1;
  }
  return res % m;
}
const long long N = 1e5 + 11;
struct node {
  long long x, y, diff;
  bool operator<(const node& other) const { return diff > other.diff; }
} v[N];
void solve() {
  long long n, m, sum = 0;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> v[i].x;
    cin >> v[i].y;
    v[i].diff = v[i].x - v[i].y;
  }
  sort(v, v + n);
  for (long long i = 0; i < n; i++) sum += v[i].x;
  for (long long i = 0; i < n; i++) {
    if (sum <= m) {
      cout << i;
      exit(0);
    }
    sum -= v[i].diff;
  }
  cout << (sum > m ? "-1" : to_string(n)) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  solve();
}
