#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmay(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vpii rxy(n),byx(n);
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        pii p=make_pair(x,y);
        rxy[i]=p;
    }
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        pii p=make_pair(y,x);
        byx[i]=p;
    }
    vb fixedr(n,false);
    int cnt=0;
    sort(rxy.begin(),rxy.end());
    sort(byx.begin(),byx.end());
    rep(bi,0,n){
        int  bx=byx[bi].second;
        int  by=byx[bi].first;
        int rfi=-1,vrf=0;
        rep(ri,0,n){
            if(fixedr[ri])continue;
            int rx,ry;
            rx=rxy[ri].first;
            ry=rxy[ri].second;
            if(rx<bx&&ry<by){
                rfi=ri;
            }
        }
        if(rfi!=-1){
            cnt++;
            fixedr[rfi]=true;
        }
    }
    cout<<cnt<<endl;
    return 0;
}



#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=1e5+10;
int n,m,p;
int head[N],vis[N],In[N];
bool Flag;
struct Edge {
  int to,last;
  Edge () {}
  Edge (int a,int b) :to(a),last(b) {}
}edge[N<<2];
void ADD(int a,int b) {
  edge[++p]=Edge(b,head[a]); head[a]=p;
  edge[++p]=Edge(a,head[b]); head[b]=p;
}
void DFS(int u,int c) {
  if(vis[u]) {
    if(vis[u]!=c) Flag=true;
    return;
  }
  vis[u]=c;
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    DFS(v,c^1);
  }
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n,m);
  for(int i=1;i<=m;++i) {
    int u,v; read(u,v);
    ADD(u,v);
    ++In[u]; ++In[v];
  }
  LL A=0,B=0,C=0;
  for(int i=1;i<=n;++i) if(!vis[i]) {
    if(!In[i]) ++A;
    else {
      Flag=false;
      DFS(i,2);
      if(Flag) ++C;
      else ++B;
    }
  }
  printf("%lld\n",A*n+A*(n-A)+B*B*2+C*C+C*B*2);
  return 0;
}
