#include<bits/stdc++.h>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define sc second
#define fs first
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


int mnx=200005, mny=200005, mxx=-200005, mxy=-200005;
vector<pii> flip(vector<pii> &v, pii p){
	int l = p.fs;
	int r = p.sc;
	vector<pii> ret;
	for(auto q: v){
		int a = q.fs;
		int b = q.sc;
		if( a == b ) continue;
		if( l == r ){
			ret.emplace_back( a, b );
		}else if( r <= a ){
			ret.emplace_back( l, r );
			ret.emplace_back( a, b );
			l = r;
		}else if( b <= l ){
			//ret.emplace_back( l, r );
			ret.emplace_back( a, b );
		}else if( a < l && r < b ){
			ret.emplace_back( a, l );
			ret.emplace_back( r, b );
			l = r;
		}else if( l <= a && r <= b ){
			ret.emplace_back( l, a );
			ret.emplace_back( r, b );
			l = r;
		}else if( l <= a && b <= r ){
			ret.emplace_back( l, a );
			l = b;
		}else if( a < l && l <= b ){
			ret.emplace_back( a, l );
			l = b;
		}
	}
	if( l != r ) ret.emplace_back(l, r);
	return ret;
}

ll sum(vector<pii> &v, int x){
	int l = 2000056;
	int r = 2000056;
	if( mnx <= x && x < mxx ){
		l = mny;
		r = mxy;
	}
	ll ret = 0;
	for(auto q: v){
		int a = q.fs;
		int b = q.sc;
		if( a == b ) continue;
		if( l == r ){
			ret += b - a;
		}else if( r <= a ){
			ret += b - a;
		}else if( b <= l ){
			ret += b - a;
		}else if( a < l && r < b ){
			ret += l - a;
			ret += b - r;
		}else if( l <= a && r <= b ){
			ret += b - r;
		}else if( l <= a && b <= r ){
		}else if( a < l && l <= b ){
			ret += l - a;
		}
	}
	return ret;
}

int main(){
	int N;
	while(cin >> N, N){
		vector<pii> v;
		rep(i,N){
			int x, y;
			cin >> x >> y;
			v.emplace_back(x, y);
		}
		mnx=200005, mny=200005, mxx=-200005, mxy=-200005;
		rep(i,4){
			int x, y;
			cin >> x >> y;
			mnx = min(mnx, x);
			mny = min(mny, y);
			mxx = max(mxx, x);
			mxy = max(mxy, y);
//cout << mnx << " " << mxx << endl;
		}
		vector<pair<int,pii>> vv;
		if( v[0].fs != v[1].fs ) v.push_back( v[0] );
		for(int i=0; i<v.size()-1; i+=2){
			if( v[i].fs != v[i+1].fs ) i++;
			int a = v[i].sc;
			int b = v[i+1].sc;
			if( a > b ) swap(a, b);
			vv.emplace_back( v[i].fs, pii(a, b) );
		}
		sort( vv.begin(), vv.end() );
				//cout << "vv:"; for(auto t: vv) cout << "(" << t.sc.fs << "," << t.sc.sc << ") "; cout << endl;
		ll ans = 0, idx=0;
		vector<pii> vp;
		for(ll x=-20000; x<=20000; x++){
			while( idx < vv.size() && vv[idx].fs == x ){
				vp = flip(vp, vv[idx].sc);
				idx++;
				//cout << "flip:"; for(auto t: vp) cout << "(" << t.fs << "," << t.sc << ") "; cout << endl;
//cout << "sum: " << ans << endl;
			}
			ans += sum(vp, x);
		}
		cout << ans << endl;
	}
	return 0;
}