#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    ll n, k, p;
    cin >> n >> k >> p;
    vector<int> A(n), B(n);
    for (auto &&i : A) scanf("%d", &i);
    for (auto &&i : B) scanf("%d", &i);
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int ng = -1, ok = p-1;
    auto f = [&](int x) -> ll {
        ll cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += upper_bound(B.begin(),B.end(), x-A[i])-lower_bound(B.begin(),B.end(), -A[i]);
            cnt += upper_bound(B.begin(),B.end(), x+p-A[i])-lower_bound(B.begin(),B.end(), p-A[i]);
        }
        return cnt;
    };
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        if(f(mid) >= k) ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
    return 0;
}