#include <bits/stdc++.h>
using namespace std;
int n, k;
int taste[110], cal[110];
int dp[110][100000 << 1];
int ans = -1;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &taste[i]);
  for (int i = 0; i < n; i++) scanf("%d", &cal[i]);
  memset(dp, -1, sizeof(dp));
  dp[0][100000] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 100000 * 2; j++) {
      int cur = taste[i - 1] - k * cal[i - 1] + j;
      if (cur < 0 && cur >= 100000 * 2) continue;
      if (dp[i - 1][j] == -1) continue;
      dp[i][cur] = max(dp[i - 1][j] + taste[i - 1], dp[i][cur]);
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
    }
  }
  if (dp[n][100000] == 0)
    ans = -1;
  else
    ans = dp[n][100000];
  printf("%d\n", ans);
  return 0;
}
