#include <bits/stdc++.h>
using namespace std;
int dp[200004];
int a[1003], b[1003];
int main() {
  int n, k;
  while (cin >> n >> k) {
    memset(dp, -0x3f3f3f3f, sizeof(dp));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    dp[10000] = 0;
    for (int i = 1; i <= n; i++) {
      int t = a[i] - k * b[i];
      if (t >= 0) {
        for (int j = 20000; j >= t; j--) {
          if (dp[j - t] != -0x3f3f3f3f) dp[j] = max(dp[j - t] + a[i], dp[j]);
        }
      } else {
        for (int j = 0; j < 20000; j++) {
          if (dp[j - t] != -0x3f3f3f3f) dp[j] = max(dp[j - t] + a[i], dp[j]);
        }
      }
    }
    if (dp[10000] == 0)
      printf("-1\n");
    else
      printf("%d\n", dp[10000]);
  }
  return 0;
}
