#include <bits/stdc++.h>
const double eps = 1e-8;
using namespace std;
inline long long read() {
  char ch = getchar();
  long long s = 0, w = 1;
  while (ch < 48 || ch > 57) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= 48 && ch <= 57) {
    s = (s << 1) + (s << 3) + (ch ^ 48);
    ch = getchar();
  }
  return s * w;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
long long n = read(), m = read(), a[100005], b[100005], c[100005];
inline bool cmp(long long a, long long b) { return a > b; }
int main() {
  long long suma = 0, sumb = 0;
  for (register long long i = 1; i <= n; i++) {
    a[i] = read(), b[i] = read(), c[i] = a[i] - b[i];
    suma += a[i], sumb += b[i];
  }
  sort(c + 1, c + 1 + n, cmp);
  if (sumb > m) {
    cout << -1 << "\n";
    return 0;
  } else {
    long long cnt = 0;
    while (suma > m) {
      suma -= c[++cnt];
    }
    cout << cnt << "\n";
  }
  return 0;
}
