#include <bits/stdc++.h>
using namespace std;
void Print(int *arr, int sz) {
  int i = 0;
  while (i < sz) {
    printf("%d ", arr[i++]);
  }
  printf("\n");
}
void init() {}
int solve() { return 0; }
vector<vector<int> > res(2, vector<int>(3 * 10e5, 0));
int main() {
  init();
  long long int t;
  {
    int N;
    int K;
    N = ({
      int t;
      scanf("%d", &t);
      t;
    });
    K = ({
      int t;
      scanf("%d", &t);
      t;
    });
    vector<int> taste(N);
    vector<int> cal(N);
    int mn = 0;
    for (int i = 0; i < N; i++) {
      taste[i] = ({
        int t;
        scanf("%d", &t);
        t;
      });
      mn += taste[i];
    }
    int mx = 0;
    for (int i = 0; i < N; i++) {
      cal[i] = ({
        int t;
        scanf("%d", &t);
        t;
      });
      cal[i] = K * cal[i];
      mx += cal[i];
    }
    for (int i = 0; i < N; i++) {
      int x = cal[i] - taste[i];
      res[1][x + 10e5] =
          (res[0][10e5] + taste[i] > res[0][x + 10e5] ? res[0][10e5] + taste[i]
                                                      : res[0][x + 10e5]);
      for (int j = -mn; j <= mx; j++) {
        if (j != 0 && j + x + 10e5 >= 0) {
          int y = (res[0][j + x + 10e5] > taste[i] + res[0][j + 10e5]
                       ? res[0][j + x + 10e5]
                       : taste[i] + res[0][j + 10e5]);
          res[1][j + x + 10e5] =
              ((res[0][j + 10e5] != 0) ? y : res[0][j + x + 10e5]);
        }
      }
      for (int j = -mn; j <= mx; j++) res[0][j + 10e5] = res[1][j + 10e5];
    }
    if (res[0][10e5] != 0)
      cout << res[0][10e5] << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
