#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int Z = 1000000;
  vector<int> p(Z, -999999);
  p[Z / 2] = 0;
  for (int i = 0; i < n; i++) {
    int t = k * b[i] - a[i];
    if (t < 0) {
      for (int j = Z - 1; j >= 0; j--) {
        if (j + t < Z && j + t >= 0) p[j] = max(p[j], p[j + t] + a[i]);
        if (p[j] < 0) p[j] = -999999;
      }
    } else if (t > 0) {
      for (int j = 0; j < Z; j++) {
        if (j + t >= 0 && j + t < Z) p[j] = max(p[j], p[j + t] + a[i]);
        if (p[j] < 0) p[j] = -999999;
      }
    } else {
      for (int j = 0; j < Z; j++) p[j] += a[i];
    }
  }
  cout << (p[Z / 2] > 0 ? p[Z / 2] : -1) << endl;
}
