#include <bits/stdc++.h>
using namespace std;
const int oo = 1047483647, maxn = 310;
const double eps = 1e-9;
int n, i, j, k, m, q, b[40], tot;
double best;
pair<double, double> a[40], S, E;
pair<double, double> r[40];
struct node {
  int w;
  pair<double, double> r;
} br[40];
double cha(pair<double, double> a, pair<double, double> b,
           pair<double, double> c) {
  double x1 = b.first - a.first, x2 = c.first - a.first;
  double y1 = b.second - a.second, y2 = c.second - a.second;
  return x1 * y2 - x2 * y1;
}
bool ok(pair<double, double> a, pair<double, double> b, pair<double, double> c,
        pair<double, double> d) {
  return cha(a, b, c) * cha(a, b, d) < eps;
}
bool getcross(pair<double, double> a, pair<double, double> b,
              pair<double, double> c, pair<double, double> d) {
  return (ok(a, b, c, d) && ok(c, d, a, b));
}
void solve() {
  for (i = 0; i <= n - 1; i++) {
    if (getcross(S, E, a[i], a[(i + 1) % n])) {
      br[++tot].w = i;
      double k =
          (double)cha(S, a[i], a[(i + 1) % n]) / cha(E, a[i], a[(i + 1) % n]);
      k = fabs(k);
      k = k / (1 + k);
      br[tot].r = make_pair(S.first + (E.first - S.first) * k,
                            S.second + (E.second - S.second) * k);
    }
  }
}
double dis(pair<double, double> a, pair<double, double> b) {
  return sqrt(((a.first - b.first) * (a.first - b.first)) +
              ((a.second - b.second) * (a.second - b.second)));
}
int ne(int x) { return (x + 1) % n; }
int pre(int x) { return (x - 1 + n) % n; }
bool cmp(const node& a, const node& b) {
  return (a.r.first < b.r.first) ||
         (a.r.first == b.r.first && a.r.second < b.r.second);
}
int main() {
  scanf("%lf%lf%lf%lf", &S.first, &S.second, &E.first, &E.second);
  scanf("%d", &n);
  for (i = 0; i <= n - 1; i++) {
    scanf("%lf%lf", &a[i].first, &a[i].second);
  }
  solve();
  sort(br + 1, br + tot + 1, cmp);
  int tt = tot;
  tot = 1;
  for (i = 2; i <= tt; i++) {
    if (fabs(br[i].r.first - br[i - 1].r.first) > eps ||
        fabs(br[i].r.second != br[i - 1].r.second) > eps)
      tot++;
    br[tot] = br[i];
  }
  if (tot != 2)
    printf("%.10f", dis(S, E));
  else {
    b[1] = br[1].w;
    r[1] = br[1].r;
    b[2] = br[2].w;
    r[2] = br[2].r;
    if (dis(S, r[1]) > dis(S, r[2])) {
      swap(r[1], r[2]);
      swap(b[1], b[2]);
    }
    best = dis(S, r[1]) + dis(r[1], r[2]) * 2 + dis(r[2], E);
    double tmp = dis(a[ne(b[1])], r[1]) + dis(a[b[2]], r[2]) + dis(S, r[1]) +
                 dis(r[2], E);
    for (i = ne(b[1]); i != b[2]; i = ne(i)) tmp += dis(a[i], a[ne(i)]);
    best = min(best, tmp);
    tmp = dis(a[b[1]], r[1]) + dis(r[2], a[ne(b[2])]) + dis(S, r[1]) +
          dis(r[2], E);
    for (i = b[1]; i != ne(b[2]); i = pre(i)) tmp += dis(a[i], a[pre(i)]);
    best = min(best, tmp);
    printf("%.9f", best);
  }
  return 0;
}
