// Sajal Asati
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mkp make_pair
#define pf push_front
#define ff first
#define ss second
// #define endl "\n"
#define lpstl(i,v) for(auto &i: v)
#define all(a) a.begin(),a.end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(a) (ll)(a.size())
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); ++it)

//containers
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int> 
#define vll vector<ll>
#define vld vector<ld>
#define vii vector<ii>
#define vpll vector<pll>
#define pq priority_queue
#define minpq priority_queue <int, vector<int>, greater<int>>

const ll init = 1e9+7;
const ll N = 1e5+7;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin>>n;
	ll sum=0;
	while(n--){
		ll a,b; cin>>a>>b;
		sum += ((a+b)*(b-a+1))/2;
	}
	cout<<sum<<endl;
	
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i,m) {cin >> a.at(i); cin >> b.at(i);}
  int k;
  cin >> k;
  vector<int> c(k);
  vector<int> d(k);
  rep(i,k) {cin >> c.at(i); cin >> d.at(i);}
  int ans = 0;
  for (int tmp = 0; tmp < (1 << k); ++tmp){
    bitset<16> bit(tmp);
    vector<int> bkt(105);
    int accc = 0;
    rep(i, k){
      if (bit.test(i)) bkt.at(d.at(i))++;
      else bkt.at(c.at(i))++;
    }
    rep(i, m){
      if (bkt.at(b.at(i)) > 0 && bkt.at(a.at(i))>0) accc++;
    }
    ans = max(ans, accc);
  }
  cout << ans << endl;
}