#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, x, y;
  cin >> n;
  vector<P> red, blue;
  vector<bool> is_pair_red(n, false), is_pair_blue(n, false);
  rep(i, n) {
    cin >> x >> y;
    red.emplace_back(y, x);
  }
  rep(i, n) {
    cin >> x >> y;
    blue.emplace_back(x, y);
  }
  sort(red.rbegin(), red.rend());
  sort(blue.begin(), blue.end());

  ll ans = 0;
  rep(i, n) {
    rep(j, n) {
      if (is_pair_red[j] || is_pair_blue[i]) continue;
      int bx = blue[i].first, by = blue[i].second;
      int rx = red[j].second, ry = red[j].first;
      if (rx < bx && ry < by) {
        is_pair_red[j] = true;
        is_pair_blue[i] = true;
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

//
// Created by tac on 2016/10/16.
//

#include <algorithm>
#include <cstdlib>
#include <string>
#include <iostream>

namespace {

void print(const std::string &str,
           std::string::size_type a,
           std::string::size_type b) {
    std::cout << str.substr(a, b - a + 1) << std::endl;
    return;
}

const std::string reverse(const std::string &str,
                          std::string::size_type a,
                          std::string::size_type b) {
    std::string ret = str;
    std::reverse(ret.begin() + a, ret.begin() + b + 1);
    return ret;
}

const std::string replace(const std::string &str,
                          std::string::size_type a,
                          std::string::size_type b,
                          const std::string &rep) {
    std::string ret = str;
    ret.replace(ret.begin() + a, ret.begin() + (b + 1), rep);
    return ret;
}

}

int main() {
    std::string str;
    int n;
    std::string op, rep;
    int a, b;
    std::cin >> str;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> op;
        std::cin >> a >> b;
        if (op == "print") {
            print(str, a, b);
        } else if (op == "reverse") {
            str = reverse(str, a, b);
        } else if (op == "replace") {
            std::cin >> rep;
            str = replace(str, a, b, rep);
        } else {
            throw std::runtime_error("");
        }
    }
    return EXIT_SUCCESS;
}