#include <bits/stdc++.h>
using namespace std;
vector<int> a, b, w;
const int MAX_MASS = 3 * 1000 * 100;
const int SHIFT = 2 * 1000 * 100;
int mass[MAX_MASS];
int main() {
  int n, k;
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  w.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    b[i] = b[i] * k;
    w[i] = a[i] - b[i];
  }
  for (int i = 0; i < MAX_MASS; ++i) {
    mass[i] = -1;
  }
  mass[SHIFT] = 0;
  for (int i = 0; i < n; ++i) {
    if (w[i] < 0) {
      for (int j = 0; j < MAX_MASS; ++j) {
        if (j - w[i] < MAX_MASS && mass[j - w[i]] != -1) {
          if (mass[j - w[i]] + a[i] > mass[j]) {
            mass[j] = mass[j - w[i]] + a[i];
          }
        }
      }
    } else {
      for (int j = MAX_MASS - 1; j >= 0; --j) {
        if (j - w[i] >= 0 && mass[j - w[i]] != -1) {
          if (mass[j - w[i]] + a[i] > mass[j]) {
            mass[j] = mass[j - w[i]] + a[i];
          }
        }
      }
    }
  }
  if (mass[SHIFT] != 0)
    cout << mass[SHIFT];
  else
    cout << -1;
  return 0;
}
