#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
	return __builtin_parity(x);
}


template<uint32_t mod>
struct ModInt{
	uint32_t a;
	ModInt& s(uint32_t vv){
		a=vv<mod?vv:vv-mod;
		return *this;
	}

	ModInt(int64_t x=0){s(x%mod+mod);}

	ModInt& operator+=(const ModInt &x){return s(a+x.a);}
	ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
	ModInt& operator*=(const ModInt &x){
		a=uint64_t(a)*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
	ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
	bool operator==(const ModInt &x)const{return a==x.a;}
	bool operator!=(const ModInt &x)const{return a!=x.a;}
	bool operator<(const ModInt &x)const{return a<x.a;}

	ModInt operator-()const{return ModInt()-*this;}
	ModInt pow(int64_t n)const{
		ModInt res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}

	ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<1000000007>;

int W;


// c m
vector<pint>ps[2];

mint dp[2][11111];

int acc[11111];

bool test[11111];

bool check(int lim){
	vector<int>cs;
	rep(i,2)for(auto p:ps[i])cs.pb(p.fi);

	sort(all(cs));
	cs.erase(unique(all(cs)),cs.end());

	int l[2]={},r[2]={};
	fill_n(*dp,2*11111,0);

	rep(i,2)dp[i][0]=1;

	for(auto x:cs){
		rep(k,2){
			while(r[k]<ps[k].size()&&ps[k][r[k]].fi-x<=lim){
				auto p=ps[k][r[k]];
				for(int j=W;j>=p.se;j--)dp[k][j]+=dp[k][j-p.se];
				r[k]++;
			}
			while(l[k]<ps[k].size()&&ps[k][l[k]].fi<x){
				auto p=ps[k][l[k]];
				for(int j=p.se;j<=W;j++)dp[k][j]-=dp[k][j-p.se];
				l[k]++;
			}
		}

		memset(acc,0,sizeof(acc));
		for(int j=1;j<=W;j++)acc[j]=acc[j-1]+(dp[1][j]!=0);
		for(int j=1;j<=W;j++){
			if(dp[0][j]==0)continue;
			if(acc[min(W,j+lim)]-acc[max(0ll,j-lim-1)])return true;
		}
	}
	return false;
}

signed main(){
	int n[2];
	cin>>n[0]>>n[1]>>W;
	rep(i,2){
		rep(j,n[i]){
			int m,c;
			cin>>m>>c;
			ps[i].eb(c,m);
		}
		sort(all(ps[i]));
	}
	

	int lb=-1,ub=1000000000;
	while(ub-lb>1){
		int mid=(ub+lb)/2;
		if(check(mid))ub=mid;
		else lb=mid;
	}
	cout<<ub<<endl;
	return 0;
}


Measured memory_bytes: 3332