#include <bits/stdc++.h>
using namespace std;
int m[101][100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(m, -10000000, sizeof(m));
  int n, k;
  cin >> n >> k;
  int a[n + 1], b[n + 1];
  int total = 0;
  int tastes = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    tastes += a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    total += b[i];
  }
  int diff;
  m[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= total * k; j++) {
      m[i][j] = max(m[i - 1][j], m[i][j]);
      diff = j + (k * b[i] - a[i]);
      diff = (diff + total * k) % (total * k);
      m[i][j] = max(m[i][j], m[i - 1][diff] + a[i]);
    }
  }
  cout << (m[n][0] <= 0 ? -1 : m[n][0]);
}
