#include <bits/stdc++.h>
using namespace std;
const int me = 20005;
const int fix = 10002;
const int mod = 1.e9 + 7;
int n, k, best = -1;
int a[105], b[105];
unordered_map<int, int> dp[105];
void _max(int &a, int b) {
  if (a < b) a = b;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) b[i] *= k;
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    for (int j = fix - 1; j > -fix; j--)
      if (dp[i - 1].count(j - a[i] + b[i]))
        _max(dp[i][j], dp[i - 1][j - a[i] + b[i]] + a[i]);
    _max(dp[i][a[i] - b[i]], a[i]);
    dp[i - 1].clear();
  }
  best = dp[n][0];
  if (!best) best = -1;
  cout << best << endl;
  return 0;
}
