#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e4 + 10;
bitset<N> b[N];
int a[N];
int w[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> w[i];
  b[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = N - 1; j >= a[i]; j--) {
      b[j] |= b[j - a[i]] << w[i];
    }
  }
  int ans = -1;
  for (int i = k; i < N; i += k) {
    if (b[i][i / k]) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
