#include <bits/stdc++.h>
long long N, i, L, R, A, B, C;
long long X[1005], Y[1005];
double W;
int main() {
  scanf("%I64d", &N);
  for (i = 1; i <= N; ++i) scanf("%I64d%I64d", &X[i], &Y[i]);
  if (Y[3] < Y[1]) L = X[1], R = X[2];
  if (Y[3] > Y[1]) L = X[2], R = X[1];
  for (i = 3; i < N; ++i) {
    if (Y[i] == Y[i + 1]) {
      if (Y[3] < Y[1] && X[i] < X[i + 1]) {
        printf("0\n");
        return 0;
      }
      if (Y[3] > Y[1] && X[i] > X[i + 1]) {
        printf("0\n");
        return 0;
      }
      continue;
    } else {
      A = Y[i] - Y[i + 1], B = X[i + 1] - X[i];
      C = X[i] * A + Y[i] * B;
      W = (C - Y[1] * B) * 1.0 / A;
    }
    if (Y[i] < Y[i + 1]) {
      if (W > 0) W += 0.999999;
      if ((int)(W) > L) L = (int)(W);
    }
    if (Y[i] > Y[i + 1]) {
      if (W < 0) W -= 0.999999;
      if ((int)(W) < R) R = (int)(W);
    }
  }
  if (R - L + 1 > 0)
    printf("%I64d\n", R - L + 1);
  else
    printf("0\n");
  return 0;
}
