#include<bits/stdc++.h>

#define pl(a) " [" << #a << ": " << (a) << "] "
#define pts(a) " [" << #a << ": { first: " << (a.first) << ", second: " << (a.second) << "}] "

#define all(vi) vi.begin(), vi.end()
#define endl "\n"
#define ll long long

using namespace std;

pair<int, int> n4[4] { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
pair<int, int> n8[8] { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1} };

ll int h(ll int x1, ll int y1, ll int x2, ll int y2) { return abs(x2 - x1) + abs(y2 - y1); }
ll int pow(ll int x, ll int y) { if (y == 0) return 1; if (y % 2 == 0) { ll int a = pow(x, y / 2); return a * a; } else { int a = pow(x, y / 2); return a * a * x; } return 0;}

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "[" << p.first << ", " << p.second << "]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; }
    
ll int pow(int x, int y) { 
    if (y == 0) return 1; 
    if (y % 2 == 0) {
        int a = pow(x, y / 2); 
        return a * a;
    } else {
        int a = pow(x, y / 2);
        return a * a * x;
    }
    assert(false);
    return 0;
}

void set_in(string s) {
    if (s.length() > 0) {
        freopen ((s+".in").c_str(), "r", stdin);
        freopen ((s+".out").c_str(), "w", stdout);
    }
}

bool intersect(pair<double, double> a, pair<double, double> b) {
    return max(a.first, b.first) <= min(a.second, b.second);
}

void solve() {
    int n; cin >> n;
    vector<pair<double, double>> arr(n);
    for (int i = 0; i < n; i++) {
        double t, a, b; cin >> t >> a >> b;

        if (t == 1);
        if (t == 2) b -= 0.1;
        if (t == 3) a += 0.1;
        if (t == 4) {a += 0.1; b -= 0.1;};
        arr[i] = {a, b};
    }

    ll int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (intersect(arr[i], arr[j])) {
                // cout << i << ' ' << j << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;
}

int main() {
#ifndef DEBUG
    set_in("");
#endif
#ifdef DEBUG
    auto clock_start = chrono::high_resolution_clock::now();
    cout << endl;
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    // int T; cin >> T;

    // for (int t = 1; t <= T; t++) {
    //     cout << "Case #" << t << ": ";
    //     solve();
    // }

    // Clock
#ifdef DEBUG
    auto clock_end = chrono::high_resolution_clock::now();
    cout << endl;
    chrono::duration<double> elapsed = clock_end - clock_start;
    cout << "Execution time: " << elapsed.count() << "s" << endl;
#endif
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N; int M; cin >> M;
  vector<ll> A(M), B(M); REP(i, M) cin >> A[i] >> B[i];
  int K; cin >> K;
  vector<ll> C(K), D(K); REP(i, K) cin >> C[i] >> D[i];
  // bit全探索
  // bitに1が立っていればDにボールを入れる
  ll ans = 0; // 最大いくつの条件が満たされているか
  // bit全探索
  for(int bit = 0; bit < (1 << K); ++bit) {
    vector<ll> t(N + 1, 0);
    for(int i = 0; i < K; ++i) {
      if(bit & (1 << i)) {
        t[C[i]]++;
      } else {
        t[D[i]]++;
      }
    }
    ll res = 0;
    REP(i, M) {
      if(t[A[i]] > 0 && t[B[i]] > 0) res++;
    }
    chmax(ans, res);
  }
  cout << ans << endl;
}
