#include <bits/stdc++.h>
using namespace std;
int d;
vector<long long> sum;
bool check(long long used, int idx) { return (used + sum[idx]) <= d; }
struct cube {
  int c;
  int w;
  cube(int _c, int _w) : c(_c), w(_w) {}
  friend bool operator<(const cube& f, const cube& s) {
    if (f.c == s.c) return f.w < s.w;
    return f.c > s.c;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m >> d;
  vector<cube> cubes1;
  for (int c, w, i = 0; i < n; i++) {
    cin >> c >> w;
    cubes1.push_back(cube(c, w));
  }
  sort(cubes1.begin(), cubes1.end());
  vector<cube> cubes2;
  for (int c, w, i = 0; i < m; i++) {
    cin >> c >> w;
    cubes2.push_back(cube(c, w));
  }
  sort(cubes2.begin(), cubes2.end());
  vector<long long> csum1(1, 0);
  for (int i = 0; i < n; i++) csum1.push_back(csum1[i] + cubes1[i].c);
  vector<long long> csum2(1, 0);
  for (int i = 0; i < m; i++) csum2.push_back(csum2[i] + cubes2[i].c);
  sum.push_back(0);
  for (int i = 0; i < m; i++) sum.push_back(sum[i] + cubes2[i].w);
  long long ans = 0;
  long long w = cubes1[0].w;
  for (int i = 1; i <= n; i++)
    if (w + cubes2[0].w <= d) {
      int l = 1, r = m;
      int res;
      while (l <= r) {
        int x = (l + r) / 2;
        if (check(w, x)) {
          l = x + 1;
          res = x;
        } else
          r = x - 1;
      }
      ans = max(ans, csum1[i] + csum2[res]);
      if (i != n) w += cubes1[i].w;
    }
  cout << ans << endl;
  return 0;
}
