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

enum {
  NONE, BLUB, BLOCK
};

int main(int argc, char *argv[]) {
  cin.sync_with_stdio(false), cin.tie(nullptr);

  int H, W, N, M;
  cin >> H >> W >> N >> M;
  vector<vector<int>> grid(H, vector<int>(W, NONE));
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    grid[x - 1][y - 1] = BLUB;
  }
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    grid[x - 1][y - 1] = BLOCK;
  }
  vector<vector<bool>> visited(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    int lastBlub = -1, lastBlock = -1;
    for (int j = 0; j < W; j++) {
      if (grid[i][j] == BLUB) {
        for (int k = lastBlock + 1; k <= j; k++) {
          visited[i][k] = true;
        }
        lastBlock = lastBlub = j;
      }
      if (grid[i][j] == BLOCK && lastBlub != -1) {
        for (int k = lastBlub + 1; k < j; k++) {
          visited[i][k] = true;
        }
      }
      if (grid[i][j] == BLOCK) {
        lastBlub = -1, lastBlock = j;
      }
    }
    if (lastBlub != -1) {
      for (int j = lastBlub + 1; j < W; j++) {
        visited[i][j] = true;
      }
    }
  }
  for (int j = 0; j < W; j++) {
    int lastBlub = -1, lastBlock = -1;
    for (int i = 0; i < H; i++) {
      if (grid[i][j] == BLUB) {
        for (int k = lastBlock + 1; k <= i; k++) {
          visited[k][j] = true;
        }
        lastBlub = lastBlock = i;
      }
      if (grid[i][j] == BLOCK && lastBlub != -1) {
        for (int k = lastBlub + 1; k < i; k++) {
          visited[k][j] = true;
        }
      }
      if (grid[i][j] == BLOCK) {
        lastBlub = -1, lastBlock = i;
      }
    }
    if (lastBlub != -1) {
      for (int i = lastBlub + 1; i < H; i++) {
        visited[i][j] = true;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans += visited[i][j];
    }
  }
  cout << ans << "\n";
}
#include<bits/stdc++.h>
using namespace std;

const long long INF = 1000000000;

typedef long long ll;

#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<ll, ll> P;
typedef pair<string, int> Psi;

vector<int> G[2100];
ll visited[2100];
ll ct=0;
void dfs(int from){
	for(int j=0;j<G[from].size(); j++){
//		cout<<from<<":"<<G[from][j]<<endl;
		if(visited[G[from][j]] !=1){
			visited[from]=1;
			visited[G[from][j]]=1;
//			cout<<G[from][j]<<endl;
			ct++;
		dfs(G[from][j]);
		}
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,m;cin>>n>>m;

	for(int i=0; i<m; i++){
		int from,to;cin>>from>>to;

		G[from].push_back(to);
	}

	ll ans =0;
	for(int i=1; i<=n; i++){
		ct=1;
		for(int a=0; a<2005; a++){
				visited[a]=0;
		}
		dfs(i);
		ans +=ct;
	}
	cout<<ans<<endl;


}
