#include <bits/stdc++.h>
using namespace std;
const int N = 50005;
map<pair<int, int>, int> mp;
map<pair<int, int>, int> at;
map<long long, bool> used;
int fa[N], nd, x1, x2, ysghysgsygsh, y2;
int x[N], y[N], ans, n;
long long hsh[N];
pair<int, int> q[N];
int getid(int x, int y) {
  if (mp.find(pair<int, int>(x, y)) == mp.end()) {
    ++nd;
    fa[nd] = nd;
    return mp[pair<int, int>(x, y)] = nd;
  }
  return mp[pair<int, int>(x, y)];
}
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
void add(int x, int y) {
  x = get(x);
  y = get(y);
  if (x != y) {
    if (x < y) swap(x, y);
    fa[x] = y;
  }
}
void insert(int sx, int sy, int tx, int ty) {
  if (pair<int, int>(sx, sy) > pair<int, int>(tx, ty))
    swap(sx, tx), swap(sy, ty);
  if (sx == tx && x1 < sx && sx < x2) {
    if (ty <= ysghysgsygsh || sy >= y2) return;
    int py1 = max(ysghysgsygsh, sy), py2 = min(y2, ty);
    add(getid(sx, py1), getid(sx, py2));
  }
  if (sy == ty && ysghysgsygsh < sy && sy < y2) {
    if (tx <= x1 || sx >= x2) return;
    int px1 = max(x1, sx), px2 = min(x2, tx);
    add(getid(px1, sy), getid(px2, sy));
  }
}
void UPDans(int px, int py, int qx, int qy) {
  if (px != -1 && py != -1) {
    long long val = hsh[getid(px, py)];
    if (used[val]) return;
    used[val] = 1;
  }
  int flg = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int sx = x[i], sy = y[i], tx = x[i % n + 1], ty = y[i % n + 1];
    if (sx != tx || sx <= qx) continue;
    if ((sy <= qy) ^ (ty <= qy)) flg ^= 1;
  }
  ans += flg;
}
int main() {
  scanf("%d%d%d%d", &x1, &y2, &x2, &ysghysgsygsh);
  for (int i = (int)(x1 + 1); i <= (int)(x2 - 1); i++) getid(i, ysghysgsygsh);
  for (int i = (int)(ysghysgsygsh + 1); i <= (int)(y2 - 1); i++) getid(x2, i);
  for (int i = (int)(x2 - 1); i >= (int)(x1 + 1); i--) getid(i, y2);
  for (int i = (int)(y2 - 1); i >= (int)(ysghysgsygsh + 1); i--) getid(x1, i);
  int tmp = nd, top = 0, flg = 0;
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d%d", &x[i], &y[i]);
  for (int i = (int)(1); i <= (int)(n); i++)
    flg |= (x[i] < x1 || x[i] > x2 || y[i] < ysghysgsygsh || y[i] > y2);
  if (!flg) return puts("1"), 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    insert(x[i], y[i], x[i % n + 1], y[i % n + 1]);
  for (int i = (int)(1); i <= (int)(tmp); i++)
    if (get(i) != i) q[++top] = pair<int, int>(i, get(i));
  if (!top)
    UPDans(-1, -1, x1, ysghysgsygsh);
  else {
    for (int i = (int)(1); i <= (int)(top); i++) {
      long long val = 1ll * i * i * i;
      hsh[q[i].second + 1] ^= val;
      hsh[q[i].first + 1] ^= val;
    }
    for (int i = (int)(1); i <= (int)(tmp); i++) hsh[i] ^= hsh[i - 1];
    for (int i = (int)(x1 + 1); i <= (int)(x2 - 1); i++)
      UPDans(i, ysghysgsygsh, i - 1, ysghysgsygsh);
    for (int i = (int)(x1 + 1); i <= (int)(x2 - 1); i++)
      UPDans(i, y2, i, y2 - 1);
    for (int i = (int)(ysghysgsygsh + 1); i <= (int)(y2 - 1); i++)
      UPDans(x2, i, x2 - 1, i - 1);
    for (int i = (int)(ysghysgsygsh + 1); i <= (int)(y2 - 1); i++)
      UPDans(x1, i, x1, i);
  }
  printf("%d\n", ans);
}
