#include <bits/stdc++.h>
using namespace std;
const int SHF = 1e5;
const int MXD = 1e5 + 1e4 + 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  for (int& x : a) cin >> x;
  for (int& x : b) {
    cin >> x;
    x *= k;
  }
  vector<vector<int>> dp(2, vector<int>(MXD, -1));
  int res = -1;
  dp[0][SHF] = 0;
  for (int i = 0; i < n; i++) {
    bool now = i & 1;
    bool nxt = !now;
    for (int j = 0; j < MXD; j++) {
      if (dp[now][j] < 0) continue;
      dp[nxt][j] = max(dp[nxt][j], dp[now][j]);
      dp[nxt][j + a[i] - b[i]] =
          max(dp[nxt][j + a[i] - b[i]], dp[now][j] + a[i]);
    }
    res = max(res, dp[nxt][SHF]);
  }
  cout << (res > 0 ? res : -1) << '\n';
}
