#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> x, pair<int, int> y) {
  return (x.first - x.second) > (y.first - y.second);
}
int main() {
  int n, m, x, y;
  long long size_before = 0L, size_after = 0L;
  vector<pair<int, int>> songs;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    songs.push_back({x, y});
    size_before += x;
    size_after += y;
  }
  if (size_after > m) {
    cout << -1 << "\n";
  } else if (size_before <= m) {
    cout << 0 << "\n";
  } else {
    sort(songs.begin(), songs.end(), cmp);
    int ans = 0;
    for (auto song : songs) {
      size_before -= (song.first - song.second);
      ans++;
      if (size_before <= m) {
        break;
      }
    }
    cout << ans << "\n";
  }
}
