#include <bits/stdc++.h>
long long h, w;
static long long get(long long x, long long y) {
  if (y == 0) {
    return x;
  }
  if (x == h) {
    return h + y;
  }
  if (y == w) {
    return h + w + (h - x);
  }
  return h + w + h + (w - y);
}
static std::vector<std::pair<long long, long long> > get(
    long long h, long long w, long long x, long long a, long long b) {
  if (a <= 0 && b <= 0) return {};
  if (a >= w && b >= w) return {};
  if (x >= h || x <= 0) return {};
  if (a > 0 && a < w && b > 0 && b < w) return {};
  int fl = 0;
  if (a > b) std::swap(a, b), fl = 1;
  std::vector<std::pair<long long, long long> > ans;
  if (a <= 0 && b >= w) {
    ans.push_back(std::make_pair(x, 0));
    ans.push_back(std::make_pair(x, w));
  } else if (a > 0) {
    ans.push_back(std::make_pair(x, w));
  } else {
    ans.push_back(std::make_pair(x, 0));
  }
  if (fl) std::reverse(ans.begin(), ans.end());
  return ans;
}
const int MAXN = 120000;
long long x[MAXN];
std::vector<long long> eds[MAXN];
int was[MAXN];
long long y[MAXN];
void add_edge(int a, int b) {
  eds[a].push_back(b);
  eds[b].push_back(a);
}
void dfs1(int v) {
  was[v] = 1;
  for (int u : eds[v]) {
    if (!was[u]) dfs1(u);
  }
}
int main(int argc, char* argv[]) {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cout.tie(0);
  long long x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  x1 *= 2, y1 *= 2, x2 *= 2, y2 *= 2;
  std::swap(y1, y2);
  h = x2 - x1;
  w = y2 - y1;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> x[i] >> y[i];
    x[i] *= 2;
    y[i] *= 2;
    x[i] -= x1;
    y[i] -= y1;
  }
  int fl = 0;
  for (int i = 0; i < n; ++i) {
    if (x[i] < 0 || y[i] < 0 || x[i] > h || y[i] > w) {
      std::rotate(x, x + i, x + n);
      std::rotate(y, y + i, y + n);
      fl = 1;
      break;
    }
  }
  if (!fl) {
    std::cout << 1 << "\n";
    return 0;
  }
  x[n] = x[0];
  y[n] = y[0];
  int cnt = 0;
  std::vector<std::pair<long long, long long> > vv;
  for (int i = 0; i < n; ++i) {
    if (x[i] == x[i + 1]) {
      auto tmp = get(h, w, x[i], y[i], y[i + 1]);
      for (auto x : tmp)
        vv.push_back(std::make_pair(get(x.first, x.second), cnt++));
    } else {
      auto tmp = get(w, h, y[i], x[i], x[i + 1]);
      for (auto x : tmp)
        vv.push_back(std::make_pair(get(x.second, x.first), cnt++));
    }
  }
  if (vv.empty()) {
    long long a = h / 2, b = w / 2;
    double ang = 0;
    for (int i = 0; i < n; ++i) {
      long long xa = x[i] - a;
      long long ya = y[i] - a;
      long long x1a = x[i + 1] - a;
      long long yb = y[i] - b;
      long long y1b = y[i + 1] - b;
      long long y1a = y[i + 1] - a;
      ang += std::atan2(xa * y1b - yb * x1a, xa * x1a + ya * y1a);
    }
    if (std::abs(ang) <= 1)
      std::cout << 0 << "\n";
    else
      std::cout << 1 << "\n";
    return 0;
  }
  for (size_t i = 0; i < vv.size(); i += 2) {
    add_edge(vv[i].second, vv[i + 1].second);
  }
  std::sort(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); ++i) {
    if (vv[i].second == 0) {
      std::rotate(vv.begin(), vv.begin() + i, vv.end());
      break;
    }
  }
  std::rotate(vv.begin(), vv.begin() + 1, vv.end());
  for (int i = 0; i < vv.size(); i += 2) {
    add_edge(vv[i].second, vv[i + 1].second);
  }
  int ans = 0;
  for (int i = 0; i < cnt; ++i) {
    if (!was[i]) dfs1(i), ++ans;
  }
  std::cout << ans << "\n";
  return 0;
}
