#include <bits/stdc++.h>
using namespace std;
long long int powm(long long int base, long long int exp) {
  long long int ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % 1000000007;
    exp >>= 1, base = (base * base) % 1000000007;
  }
  return ans;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int a[n + 1], b[n + 1], d[n + 1], o = 0, c = 0, ans = 0;
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    d[i] = a[i] - b[i];
    o += a[i];
    c += b[i];
  }
  if (c > m) {
    cout << -1;
    return 0;
  }
  sort(d + 1, d + n + 1);
  for (int i = n; i >= 1; i--) {
    if (o > m) {
      o -= d[i];
      ans += 1;
    } else
      break;
  }
  cout << ans;
}
