#include <bits/stdc++.h>
using namespace std;
long long inf1 = 1e18;
int mid = 100001;
int dp[105][200010];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  int b[n], a[n];
  for (int i = (0); i < (n); i++) cin >> b[i];
  for (int i = (0); i < (n); i++) cin >> a[i];
  for (int i = (0); i < (n); i++) a[i] = b[i] - a[i] * k;
  int ans;
  dp[0][mid + a[0]] = b[0];
  ans = dp[0][mid];
  for (int i = (1); i < (n); i++) {
    dp[i][mid + a[i]] = b[i];
    for (int j = (0); j < (200010); j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if (dp[i - 1][j] != 0)
        dp[i][j + a[i]] = max(dp[i][j + a[i]], dp[i - 1][j] + b[i]);
    }
    ans = max(ans, dp[i][mid]);
  }
  ans == 0 ? cout << -1 : cout << ans;
}
