import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Euler742 {

    static class Edge implements Comparable<Edge> {
        int x, y;

        Edge(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Edge other) {
            long lhs = (long) this.x * other.y;
            long rhs = (long) other.x * this.y;
            return Long.compare(lhs, rhs);
        }
    }

    static int gcd(int a, int b) {
        while (b != 0) {
            int t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    static List<Edge> getEdgeCandidates(int numEdges) {
        int[][] primitive = new int[numEdges + 1][numEdges + 1];
        for (int y = 1; y <= numEdges; ++y) {
            for (int x = 1; x < y; ++x) {
                if (gcd(x, y) == 1) {
                    primitive[y][x] = 1;
                }
            }
        }

        int[][] pref = new int[numEdges + 1][numEdges + 1];
        for (int y = 1; y <= numEdges; ++y) {
            int row = 0;
            for (int x = 1; x <= numEdges; ++x) {
                row += primitive[y][x];
                pref[y][x] = pref[y - 1][x] + row;
            }
        }

        List<Edge> edges = new ArrayList<>();
        for (int y = 1; y <= numEdges; ++y) {
            for (int x = 1; x < y; ++x) {
                if (primitive[y][x] == 0)
                    continue;
                int countSmallerEdges = pref[y][x];
                if (2 + countSmallerEdges > numEdges)
                    break;
                edges.add(new Edge(x, y));
            }
        }
        Collections.sort(edges);
        return edges;
    }

    static class SAPair implements Comparable<SAPair> {
        int s;
        long a;

        SAPair(int s, long a) {
            this.s = s;
            this.a = a;
        }

        @Override
        public int compareTo(SAPair o) {
            if (this.s != o.s) {
                return Integer.compare(this.s, o.s);
            }
            return Long.compare(this.a, o.a);
        }
    }

    static List<SAPair> filterConvexHull(List<SAPair> domain) {
        Collections.sort(domain);
        List<SAPair> out = new ArrayList<>(domain.size());

        for (SAPair cur : domain) {
            int s = cur.s;
            long a = cur.a;

            if (!out.isEmpty() && out.get(out.size() - 1).s == s)
                continue;

            while (out.size() >= 2) {
                int s1 = out.get(out.size() - 1).s;
                long a1 = out.get(out.size() - 1).a;
                int s2 = out.get(out.size() - 2).s;
                long a2 = out.get(out.size() - 2).a;

                BigInteger diffAS1 = BigInteger.valueOf(a - a1);
                BigInteger diffSS2 = BigInteger.valueOf(s - s2);
                BigInteger diffAS2 = BigInteger.valueOf(a - a2);
                BigInteger diffSS1 = BigInteger.valueOf(s - s1);

                BigInteger lhs = diffAS1.multiply(diffSS2);
                BigInteger rhs = diffAS2.multiply(diffSS1);

                if (lhs.compareTo(rhs) >= 0)
                    break;
                out.remove(out.size() - 1);
            }

            if (!out.isEmpty() && out.get(out.size() - 1).a <= a)
                continue;
            out.add(cur);
        }
        return out;
    }

    static List<SAPair> combineConvexHulls(List<SAPair> d0, List<SAPair> d1) {
        List<SAPair> merged = new ArrayList<>(d0.size() + d1.size());
        int i = 0, j = 0;
        while (i < d0.size() && j < d1.size()) {
            if (d0.get(i).compareTo(d1.get(j)) <= 0) {
                merged.add(d0.get(i++));
            } else {
                merged.add(d1.get(j++));
            }
        }
        while (i < d0.size())
            merged.add(d0.get(i++));
        while (j < d1.size())
            merged.add(d1.get(j++));
        return filterConvexHull(merged);
    }

    static List<SAPair> updateSADomain(List<SAPair> domain, Edge edge) {
        List<SAPair> out = new ArrayList<>(domain.size());
        int x = edge.x;
        int y = edge.y;
        for (SAPair p : domain) {
            int ns = p.s + 2 * y;
            long na = p.a + 2L * x * (p.s + y);
            out.add(new SAPair(ns, na));
        }
        return out;
    }

    public static String solve() {
        int numEdges = 1000;
        if (numEdges < 4 || (numEdges % 4) != 0)
            return "-1";
        int qEdges = numEdges / 4;
        if (qEdges == 1)
            return "1";

        List<List<SAPair>> domain = new ArrayList<>(qEdges + 1);
        for (int i = 0; i <= qEdges; ++i) {
            domain.add(new ArrayList<>());
        }
        domain.get(1).add(new SAPair(1, 0L));

        List<Edge> edges = getEdgeCandidates(qEdges);

        for (Edge edge : edges) {
            for (int used = qEdges - 1; used >= 1; --used) {
                if (domain.get(used).isEmpty())
                    continue;
                List<SAPair> withNew = updateSADomain(domain.get(used), edge);
                domain.set(used + 1, combineConvexHulls(domain.get(used + 1), withNew));
            }
        }

        long best = 1L << 62;
        for (int left = 1; left < qEdges; ++left) {
            List<SAPair> d0 = domain.get(left);
            List<SAPair> d1 = domain.get(qEdges - left);
            for (SAPair p0 : d0) {
                for (SAPair p1 : d1) {
                    long val = p0.a + p1.a + (long) (p0.s + 2) * (p1.s + 2) - 2;
                    if (val < best) {
                        best = val;
                    }
                }
            }
        }

        return Long.toString(best);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
