#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
bool compare(const std::pair<int, int>& i, const std::pair<int, int>& j) {
  return i.first - i.second > j.first - j.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, a, b, sum = 0;
  pair<long long, long long> t[100000];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    t[i] = {a, b};
    sum += a;
  }
  sort(t, t + n, compare);
  long long ans = 0, i = 0;
  while (sum > m && i < n) {
    sum -= (t[i].first - t[i].second);
    i++;
    ans++;
  }
  cout << (sum <= m ? ans : -1);
}
