#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int X[16000][2];
int L[2][2];
int main() {
  for (int i = (0); i < (2); i++)
    for (int j = (0); j < (2); j++) cin >> L[i][j];
  int N;
  cin >> N;
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++) cin >> X[i][j];
  swap(L[0][1], L[1][1]);
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++)
      X[i][j] = max(min(X[i][j], L[1][j]), L[0][j]);
  vector<pair<int, int> > actions;
  bool allinside = true;
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++)
      for (int k = (0); k < (2); k++)
        if (X[i][j] == L[k][j]) allinside = false;
  if (allinside) {
    cout << 1 << endl;
    return 0;
  }
  map<int, int> adj;
  for (int i = (0); i < (N); i++) {
    int ii = (i + 1) % N;
    bool edgetravel = false;
    for (int k = (0); k < (2); k++)
      for (int j = (0); j < (2); j++)
        if (X[i][k] == L[j][k] && X[ii][k] == L[j][k]) edgetravel = true;
    if (edgetravel) continue;
    allinside = true;
    for (int k = (0); k < (2); k++)
      for (int j = (0); j < (2); j++)
        if (X[i][k] == L[j][k] || X[ii][k] == L[j][k]) allinside = false;
    int L0 = 0;
    pair<int, int> a1(-1, -1);
    pair<int, int> a2(-1, -1);
    if (X[i][1] == L[0][1]) {
      a1 = (make_pair(L0 + X[i][0] - L[0][0], 1));
    }
    if (X[ii][1] == L[0][1]) {
      a2 = (make_pair(L0 + X[ii][0] - L[0][0], 0));
    }
    L0 += L[1][0] - L[0][0];
    if (X[i][0] == L[1][0]) {
      a1 = (make_pair(L0 + X[i][1] - L[0][1], 1));
    }
    if (X[ii][0] == L[1][0]) {
      a2 = (make_pair(L0 + X[ii][1] - L[0][1], 0));
    }
    L0 += L[1][1] - L[0][1];
    if (X[i][1] == L[1][1]) {
      a1 = (make_pair(L0 - X[i][0] + L[1][0], 1));
    }
    if (X[ii][1] == L[1][1]) {
      a2 = (make_pair(L0 - X[ii][0] + L[1][0], 0));
    }
    L0 += L[1][0] - L[0][0];
    if (X[i][0] == L[0][0]) {
      a1 = (make_pair(L0 - X[i][1] + L[1][1], 1));
    }
    if (X[ii][0] == L[0][0]) {
      a2 = (make_pair(L0 - X[ii][1] + L[1][1], 0));
    }
    if (a1.first != -1) actions.push_back(a1);
    if (a2.first != -1) actions.push_back(a2);
  }
  int last = -1;
  for (auto it : actions) {
    if (it.second)
      last = it.first;
    else
      last = -1;
  }
  for (auto it : actions) {
    if (it.second) {
      assert(last == -1);
      last = it.first;
    } else {
      adj[last] = it.first;
      last = -1;
    }
  }
  sort((actions).begin(), (actions).end());
  last = -1;
  for (auto it : actions) {
    if (!it.second)
      last = it.first;
    else
      last = -1;
  }
  for (auto it : actions) {
    if (!it.second) {
      assert(last == -1);
      last = it.first;
    } else {
      adj[last] = it.first;
      last = -1;
    }
  }
  int res = 0;
  unordered_set<int> vis;
  for (auto it : actions) {
    int p = it.first;
    if (vis.find(p) != vis.end()) continue;
    ++res;
    while (vis.find(p) == vis.end()) {
      vis.insert(p);
      assert(adj.find(p) != adj.end());
      p = adj[p];
    }
  }
  if (res == 0) {
    long long A = 0;
    for (int i = (1); i < (N + 1); i++) {
      long long d = (long long)X[i - 1][0] * X[i % N][1] -
                    (long long)X[i % N][0] * X[i - 1][1];
      A += d;
    }
    if (A) res = 1;
  }
  cout << res << endl;
  return 0;
}
