#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000000;
int n, m, a[105], b[105], f[105][200020];
int val(int x) { return x + 100005; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    b[i] = a[i] - b[i] * m;
  }
  fill(f[0] + 1, f[0] + 200005, -oo);
  f[0][val(0)] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = -100000; j < 100001; j++) {
      f[i][val(j)] = f[i - 1][val(j)];
      if (j - b[i] > -100001 && j - b[i] < 100001) {
        f[i][val(j)] = max(f[i][val(j)], f[i - 1][val(j - b[i])] + a[i]);
      }
    }
  }
  cout << (f[n][val(0)] > 0 ? f[n][val(0)] : -1) << "\n";
  return 0;
}
