#include <bits/stdc++.h>
using namespace std;
struct salad {
  int a, b, c;
} salad[1001];
int dp[105][50005], n, k;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> salad[i].a;
  for (int i = 1; i <= n; i++) {
    cin >> salad[i].b;
    salad[i].c = salad[i].a - k * salad[i].b;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][10000] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 50000; j++) {
      if (dp[i - 1][j] == -1 && dp[i - 1][j - salad[i].c] == -1)
        continue;
      else if (dp[i - 1][j - salad[i].c] != -1)
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - salad[i].c] + salad[i].a);
      else
        dp[i][j] = dp[i - 1][j];
    }
  if (dp[n][10000] == 0)
    cout << -1;
  else
    cout << dp[n][10000];
  return 0;
}
