#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000000;
int N, K;
int a[5000], b[5000];
int dp[101][100010 * 2];
const int M = 100000;
int main() {
  while (~scanf("%d%d", &N, &K)) {
    for (int i = 1; i <= N; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= N; ++i) {
      scanf("%d", &b[i]);
      b[i] *= K;
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0 + M] = 0;
    for (int i = 1; i <= N; ++i) {
      int x = a[i] - b[i];
      for (int j = M; j >= -M; --j) {
        dp[i][j + M] = dp[i - 1][j + M];
        if (j - x >= -M && dp[i - 1][j - x + M] > -1) {
          dp[i][j + M] = max(dp[i - 1][j - x + M] + a[i], dp[i][j + M]);
        }
      }
    }
    if (dp[N][M] == 0)
      printf("-1\n");
    else
      printf("%d\n", dp[N][M]);
  }
  return 0;
}
