#include <bits/stdc++.h>
using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int MOD = 1e9 + 7;
struct HASH {
  size_t operator()(const int& x) const { return (x + 1e5); }
};
class MainClass {
 public:
  void solve() {
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> v(n);
    for (auto& [a, b] : v) cin >> a;
    for (auto& [a, b] : v) cin >> b;
    vector<unordered_map<int, int, HASH>> dp(n + 1);
    for (int i = 0; i < n; i++) {
      auto& zer = dp[i][0];
      zer = max(zer, 0);
      auto [a, b] = v[i];
      for (auto [val, maxa] : dp[i]) {
        auto& dont = dp[i + 1][val];
        dont = max(dont, maxa);
        auto& choose = dp[i + 1][val + a - k * b];
        choose = max(choose, maxa + a);
      }
    }
    auto ans = dp[n][0];
    cout << (ans == 0 ? -1 : ans);
    return;
  }
};
int main() {
  int test = 1;
  for (int tst = 1; tst <= test; ++tst) {
    MainClass Ausmosian;
    Ausmosian.solve();
    cout << "\n";
  }
  return 0;
}
