#include <bits/stdc++.h>
void comp(char* r, int* o, int nr, int* v, int* av, int nv) {
  for (int i = 0; i <= nr; i++) {
    r[i] = 0;
    o[i] = 0;
  }
  r[0] = 1;
  for (int i = 0; i < nv; i++) {
    int vi = v[i], avi = av[i];
    for (int j = nr - 1; j >= 0; j--) {
      if (r[j]) {
        r[j + vi] = 1;
        o[j + vi] = std::max(o[j + vi], avi + o[j]);
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, k;
  std::cin >> n >> k;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    std::cin >> b[i];
  }
  int opt = 0, npoz = 0, nneg = 0, spoz = 0, sneg = 0;
  int poz[n], neg[n], apoz[n], aneg[n];
  for (int i = 0; i < n; i++) {
    int t = a[i] - k * b[i];
    if (t == 0) {
      opt += a[i];
      continue;
    }
    if (t > 0) {
      poz[npoz] = t;
      apoz[npoz] = a[i];
      npoz++;
      spoz += t;
      continue;
    }
    t = (-t);
    neg[nneg] = t;
    aneg[nneg] = a[i];
    nneg++;
    sneg += t;
  }
  if (nneg > 0 && npoz > 0) {
    char* r_neg = new char[sneg + 1];
    int* o_neg = new int[sneg + 1];
    char* r_poz = new char[spoz + 1];
    int* o_poz = new int[spoz + 1];
    int smin = std::min(sneg, spoz);
    comp(r_neg, o_neg, smin, neg, aneg, nneg);
    comp(r_poz, o_poz, smin, poz, apoz, npoz);
    int mx = 0;
    for (int i = 1; i <= smin; i++) {
      if (r_neg[i] && r_poz[i]) {
        mx = std::max(o_neg[i] + o_poz[i], mx);
      }
    }
    opt += mx;
    delete[] r_neg;
    delete[] o_neg;
    delete[] r_poz;
    delete[] o_poz;
  }
  if (opt > 0) {
    std::cout << opt << "\n";
  } else {
    std::cout << "-1\n";
  }
  return 0;
}
