Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side n. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0, 0), (n, 0), (0, n) and (n, n).

Input

The single line contains 5 space-separated integers: n, x1, y1, x2, y2 (1 ≤ n ≤ 1000, 0 ≤ x1, y1, x2, y2 ≤ n) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.

Output

You must print on a single line the shortest distance between the points.

Examples

Input

2 0 0 1 0


Output

1


Input

2 0 1 2 1


Output

4


Input

100 0 0 100 100


Output

200
import java.io.*;
import java.util.*;

public class CF57_65 {
    static BufferedReader br = null;
    static PrintWriter pw = null;
    static StringTokenizer st = null;
    static String FILENAME = "";

    void nline() {
        try {
            st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    int ni() {
        while (st == null || !st.hasMoreTokens())
            nline();
        return Integer.parseInt(st.nextToken());
    }

    long nl() {
        while (st == null || !st.hasMoreTokens())
            nline();
        return Long.parseLong(st.nextToken());
    }

    double nd() {
        while (st == null || !st.hasMoreTokens())
            nline();
        return Double.parseDouble(st.nextToken());
    }

    String ns() {
        while (st == null || !st.hasMoreTokens())
            nline();
        return st.nextToken();
    }

    String nstr() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return s;
    }

    class Point implements Comparable<Point> {
        long x, y;

        public Point(long x, long y) {
            super();
            this.x = x;
            this.y = y;
        }

        public int compareTo(Point o) {
            if (x < o.x)
                return -1;
            if (x == o.x && y < o.y)
                return -1;
            if (x == o.x && y == o.y)
                return 0;
            return 1;
        }

    }

    boolean cw(Point a, Point b, Point c) {
        return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0;
    }

    boolean ccw(Point a, Point b, Point c) {
        return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
    }

    public void solve() {
        int n = ni();
        int x1 = ni();
        int y1 = ni();
        int x2 = ni();
        int y2 = ni();
        if ((x1 == x2 && (x1 == n || x1 == 0))
                || (y1 == y2 && (y1 == n || y1 == 0))) {
            pw.println(Math.abs(x1 - x2) + Math.abs(y1 - y2));
            return;
        }
        int[] x = { 0, 0, n, n };
        int[] y = { 0, n, 0, n };
        int min = 4 * n;
        for (int i = 0; i < 4; i++) {
            int d = 0;
            if (x1 == x[i] || y1 == y[i])
                d += Math.abs(x1 - x[i]) + Math.abs(y1 - y[i]);
            else
                continue;
            if (x2 == x[i] || y2 == y[i])
                d += Math.abs(x2 - x[i]) + Math.abs(y2 - y[i]);
            else
                continue;
            if (d < min)
                min = d;
        }
        for (int i = 0; i < 4; i++)
            for (int j = 0; j < 4; j++) {
                int d = 0;
                if (x1 == x[i] || y1 == y[i])
                    d += Math.abs(x1 - x[i]) + Math.abs(y1 - y[i]);
                else
                    continue;
                if (x[j] == x[i] || y[j] == y[i])
                    d += Math.abs(x[j] - x[i]) + Math.abs(y[j] - y[i]);
                else
                    continue;
                if (x2 == x[j] || y2 == y[j])
                    d += Math.abs(x2 - x[j]) + Math.abs(y2 - y[j]);
                else
                    continue;
                if (d < min)
                    min = d;
            }
        pw.println(min);
    }

    public void run() {
        solve();
        pw.close();
    }

    public static void main(String[] args) {
        if (System.getProperty("ONLINE_JUDGE") != null) {
            br = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            new CF57_65().run();
        } else {
            int testCount = 3;
            String[] inputData = { "2 0 0 1 0\n", "2 0 1 2 1\n",
                    "100 0 0 100 100\n" };
            String[] outputData = { "1\n", "4\n", "200\n" };
            for (int testNum = 0; testNum < testCount; testNum++) {
                System.out.printf("Runing test case #%d:\n", testNum);
                br = new BufferedReader(new StringReader(inputData[testNum]));
                StringWriter sw = new StringWriter();
                pw = new PrintWriter(sw);
                long startTime = System.currentTimeMillis();
                new CF57_65().run();
                pw.flush();
                long endTime = System.currentTimeMillis();
                String result = sw.toString();
                System.out.printf("Time of execution %d ms\n",
                        (endTime - startTime));
                if (result.trim().compareTo(outputData[testNum]) == 0)
                    System.out.println("OK");
                else {
                    System.out.println("FAILED");
                    System.out.printf("Sample:\n%s\nResult:\n%s\n",
                            outputData[testNum], result);
                }
                pw.close();
            }
        }
    }

}
