#include <bits/stdc++.h>
#define ll        long long int
#define ld        long double
#define pi        pair<int,int>
#define all(x)    x.begin(), x.end()
#define allr(x)   x.rbegin(), x.rend()
#define sz(x)     ((int)x.size())
#define ln(x)     ((int)x.length())
#define mp        make_pair
#define pb        push_back
#define ff        first
#define ss        second
#define endl      '\n'
#define dbg(x)    cout << #x << ": " << x << endl
#define clr(x,v)  memset(x, v, sizeof(x))
#define fix(x)    cout << setprecision(x) << fixed;
#define FASTIO    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const ll inf = 1LL << 30;
const int MAXN = 1e5 + 5;

vector<vector<int>> row, col;

void cp()
{
    int n, m, p, q;
    cin >> n >> m >> p >> q;
    row = vector<vector<int>>(n + 1, vector<int>(m + 1));
    col = vector<vector<int>>(n + 1, vector<int>(m + 1));
    vector<vector<int>> block_row(n), block_col(m);
    vector<vector<int>> bulb_row(n), bulb_col(m);
    for(int i = 0, x, y; i < p; i++)
        cin >> x >> y, x--, y--, bulb_row[x].pb(y), bulb_col[y].pb(x);
    for(int i = 0, x, y; i < q; i++)
        cin >> x >> y, x--, y--, block_row[x].pb(y), block_col[y].pb(x);

    for(int i = 0; i < n; i++)
    {
        sort(all(block_row[i]));
        for(int x : bulb_row[i])
        {
            // find left block
            int left = -1;
            int lo = 0, hi = sz(block_row[i]) - 1;
            while(lo <= hi)
            {
                int mid = (lo + hi) >> 1;
                if(block_row[i][mid] < x)
                    left = block_row[i][mid], lo = mid + 1;
                else
                    hi = mid - 1;
            }
            // find right block
            int right = m;
            lo = 0, hi = sz(block_row[i]) - 1;
            while(lo <= hi)
            {
                int mid = (lo + hi) >> 1;
                if(block_row[i][mid] > x)
                    right = block_row[i][mid], hi = mid - 1;
                else
                    lo = mid + 1;
            }
            left++, right--;
            row[i][left]++;
            row[i][right + 1]--;
        }

        for(int j = 1; j < m; j++)
            row[i][j] += row[i][j - 1];
    }
    
    for(int i = 0; i < m; i++)
    {
        sort(all(block_col[i]));
        for(int x : bulb_col[i])
        {
            // find top block
            int top = -1;
            int lo = 0, hi = sz(block_col[i]) - 1;
            while(lo <= hi)
            {
                int mid = (lo + hi) >> 1;
                if(block_col[i][mid] < x)
                    top = block_col[i][mid], lo = mid + 1;
                else
                    hi = mid - 1;
            }
            // find bottom block
            int bottom = n;
            lo = 0, hi = sz(block_col[i]) - 1;
            while(lo <= hi)
            {
                int mid = (lo + hi) >> 1;
                if(block_col[i][mid] > x)
                    bottom = block_col[i][mid], hi = mid - 1;
                else
                    lo = mid + 1;
            }
            top++, bottom--;
            col[top][i]++;
            col[bottom + 1][i]--;
        }

        for(int j = 1; j < n; j++)
            col[j][i] += col[j - 1][i];
    }

    int ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            ans += (row[i][j] || col[i][j]);
    cout << ans << endl;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

// #define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }

int INF = 1e18;
int MOD = 1e9+7;

void solve()
{
    int n, t; cin>>n>>t;
    vi small, big;
    rep(i, 0, n/2) {
        int temp; cin>>temp;
        small.pb(temp);
    }
    rep(i, 0, n-small.size()) {
        int temp; cin>>temp;
        big.pb(temp);
    }
    sort(small.begin(), small.end());
    sort(big.begin(), big.end());
    set<int> sSum, bSum;
    int nn = small.size();
    int allOne = 1LL<<nn;
    rep(mask, 0, allOne) {
        int sum = 0;
        rep(s, 0, nn) {
            if(mask&(1LL<<s))
                sum += small[s];
        }
        sSum.insert(sum);
    }
    nn = big.size();
    allOne = 1LL<<nn;
    rep(mask, 0, allOne) {
        int sum = 0;
        rep(s, 0, nn) {
            if(mask&(1LL<<s))
                sum += big[s];
        }
        bSum.insert(sum);
    }
    int ans = 0;
    for(int sum: sSum) {
        auto ptr = bSum.upper_bound(t-sum);
        int rem = *prev(ptr);
        if(rem+sum <= t) ans = max(ans, rem+sum);
    }
    for(int sum: bSum) {
        auto ptr = sSum.upper_bound(t-sum);
        int rem = *prev(ptr);
        if(rem+sum <= t) ans = max(ans, rem+sum);
    }
    cout<<ans<<endl;
}   

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    rep(i, 0, t)
    {
        solve();
    }
    return 0;
}
