#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

const int MN = 1010;
const int MW = 10010;
const int MD = 1e9+114514;
int n;
int W;
int c[MN], t[MN], w[MN]; // cute, type, weight

int dp[2][MW];
int sm[MW+1];
bool solve(int md) {
//    printf("solve %d %d\n", n, md);

    memset(dp, 0, sizeof(dp));
    dp[0][0] = dp[1][0] = 1;

    int r = 0;
    for (int l = 0; l < n; l++) {
        while (r < n && c[r] - c[l] <= md) {
            // insert r
            for (int i = W; i >= w[r]; i--) {
                dp[t[r]][i] += dp[t[r]][i - w[r]];
            }
            r++;
        }
//        printf("%d %d\n", l, r);
        // check

        // for (int i = 0; i < 2; i++) {
        //     printf("dp table %d\n", i);
        //     for (int j = 0; j <= W; j++) {
        //         printf("%d ", dp[i][j]);
        //     }
        //     printf("\n");
        // }
        sm[0] = 0;
        for (int i = 1; i <= MW; i++) {
            sm[i] = sm[i-1];
            if (dp[1][i-1]) sm[i]++;
        }

        for (int i = 1; i < MW; i++) {
            if (!dp[0][i]) continue;
            if (sm[min(W+1, i+md+1)] != sm[max(1, i-md)]) return true;
        }
        // erase l
        for (int i = w[l]; i <= W; i++) {
            dp[t[l]][i] -= dp[t[l]][i - w[l]];
        }
    }
    return false;
}

int main() {
    int na, nb;
    cin >> na >> nb >> W;
    n = na + nb;
    static T tt[MN];
    for (int i = 0; i < na; i++) {
        int m, c;
        cin >> m >> c;
        tt[i] = T(c, 0, m);
    }
    for (int i = 0; i < nb; i++) {
        int m, c;
        cin >> m >> c;
        tt[na+i] = T(c, 1, m);
    }

    sort(tt, tt+n);

    for (int i = 0; i < n; i++) {
        tie(c[i], t[i], w[i]) = tt[i];
    }
    int l = -1, r = 1e9+10;
    while (r - l > 1) {
        int md = (l+r)/2;
        if (!solve(md)) {
            l = md;
        } else {
            r = md;
        }
    }
    cout << r << endl;
    return 0;
}