#include <bits/stdc++.h>
using namespace std;
const int tmax = 1e5 + 5, delta = 1e5 + 1;
int n, k, f[tmax * 2], g[tmax * 2], a[tmax], b[tmax];
int main() {
  scanf("%d%d", &n, &k);
  int i, j;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    b[i] = a[i] - k * b[i];
  }
  memset(g, -1, sizeof(g));
  memset(f, -1, sizeof(f));
  g[0 + delta] = 0;
  f[0 + delta] = 0;
  for (i = 1; i <= n; i++) {
    for (j = -100000 + delta; j <= 10000 + delta; j++)
      if (j - b[i] >= 0 && j - b[i] <= 10000 + delta && g[j - b[i]] != -1)
        f[j] = max(g[j], g[j - b[i]] + a[i]);
    memcpy(g, f, sizeof(f));
  }
  printf("%d", f[0 + delta] == 0 ? -1 : f[0 + delta]);
  return 0;
}
