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.InputMismatchException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author el-Bishoy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        int matrix[][];
        int dx[] = {1, -1, 0, 0};
        int dy[] = {0, 0, -1, 1};
        boolean[][] visited;
        int min = Integer.MAX_VALUE;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();

            matrix = new int[n + 1][n + 1];
            visited = new boolean[n + 1][n + 1];

//        for (int i = 0; i <= n; i++) { matrix[0][i] = 1; }
//        for (int i = 0; i <= n; i++) { matrix[i][0] = 1; }
//        for (int i = 0; i <= n; i++) { matrix[n][i] = 1; }
//        for (int i = 0; i <= n; i++) { matrix[i][n] = 1; }

            for (int i = 0; i <= n; i++) {
                matrix[0][i] = 1;
            }
            for (int i = 0; i <= n; i++) {
                matrix[i][0] = 1;
            }
            for (int i = 0; i <= n; i++) {
                matrix[n][i] = 1;
            }
            for (int i = 0; i <= n; i++) {
                matrix[i][n] = 1;
            }

            int x = 0;

            dfs(x1, y1, x2, y2, 0);

            out.println(min);
        }

        void dfs(int r, int c, int x2, int y2, int path) {

            if (matrix[r][c] == 0) return;
            visited[r][c] = true;

            if (x2 == r && y2 == c) {
                min = Math.min(min, path);
                visited[r][c] = false;
                return;
            }
            for (int i = 0; i < 4; i++) {
                int newR = r + dy[i];
                int newC = c + dx[i];
                if (validIdx(newR, newC, visited.length, visited.length) && !visited[newR][newC])
                    dfs(newR, newC, x2, y2, path + 1);
            }

        }

        boolean validIdx(int r, int c, int n, int m) {
            return r >= 0 && r < n && c >= 0 && c < m;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

