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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  vector<int> c(m), d(m);
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];
  vector<vector<int>> grid(h, vector<int>(w, 0));
  for (int i = 0; i < n; i++) {
    --a[i];
    --b[i];
    grid[a[i]][b[i]] = 1;
  }
  for (int i = 0; i < m; i++) {
    --c[i];
    --d[i];
    grid[c[i]][d[i]] = 2;
  }
  vector<vector<bool>> rowp(h, vector<bool>(w));
  vector<vector<bool>> rows(h, vector<bool>(w));
  vector<vector<bool>> colp(h, vector<bool>(w));
  vector<vector<bool>> cols(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    bool ok = false;
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == 2) {
        ok = false;
      } else if (grid[i][j] == 1) {
        ok = true;
      }
      rowp[i][j] = ok;
    }
    ok = false;
    for (int j = w - 1; j >= 0; j--) {
      if (grid[i][j] == 2) {
        ok = false;
      } else if (grid[i][j] == 1) {
        ok = true;
      }
      rows[i][j] = ok;
    }
  }
  for (int i = 0; i < w; i++) {
    bool ok = false;
    for (int j = 0; j < h; j++) {
      if (grid[j][i] == 2) {
        ok = false;
      } else if (grid[j][i] == 1) {
        ok = true;
      }
      colp[j][i] = ok;
    }
    ok = false;
    for (int j = h - 1; j >= 0; j--) {
      if (grid[j][i] == 2) {
        ok = false;
      } else if (grid[j][i] == 1) {
        ok = true;
      }
      cols[j][i] = ok;
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == 0 || grid[i][j] == 1) {
        int cur = rowp[i][j] || rows[i][j] || colp[i][j] || cols[i][j];
        res += cur;
      }
    }
  }
  cout << res << '\n';
  return 0;
}
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> graph;
vector<bool> visit(2000);

void  dfs(int now_town){
    
    
    if(visit[now_town]){
        return;
    }
    
    visit[now_town] = true;
    for(auto next_town : graph[now_town]){
        dfs(next_town);
    }
}


int main(void){
    
    int N, M;
    cin >> N >> M;
    
    graph.resize(N);
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        
        graph[A-1].push_back(B-1);
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++){
        
        for(int j = 0; j < N; j++){
            visit[j] = false;
        }
        dfs(i);
        
        for(int j = 0; j < N; j++){
            if(visit[j]) ans++;
        }
    }
    
    cout << ans << endl;
}
