#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e4 + 5;
int n, k;
int a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn];
int main() {
  scanf("%d%d", &n, &k);
  memset(dp1, -0x3f, sizeof(dp1));
  memset(dp2, -0x3f, sizeof(dp2));
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    c[i] = b[i] * k - a[i];
  }
  dp1[0] = dp2[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i] >= 0) {
      for (int v = 10000; v >= c[i]; v--)
        dp1[v] = max(dp1[v], dp1[v - c[i]] + a[i]);
    } else {
      for (int v = 10000; v >= -c[i]; v--)
        dp2[v] = max(dp2[v], dp2[v + c[i]] + a[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i <= 10000; i++) ans = max(ans, dp1[i] + dp2[i]);
  if (ans)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
