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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Trung Pham
 */
public class A {

    public static String[] ps = {"rock", "paper", "scissors"};

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        //  System.out.println(1e-4);

        int n = in.nextInt();
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();
        if ((x1 == x2 && (x1 == 0 || x1 == n)) || (y1 == y2 && (y1 == 0 || y1 == n))) {
            
            out.println(Math.abs(x1 - x2) + Math.abs(y1 - y2));
        } else {
            boolean found = false;
            double e = dist(x1, y1, 0, 0);
            double g = dist(x2, y2, 0, 0);
            //System.out.println(e + " " + g);
            if (e == (int) e && g == (int) g) {
                out.println((int) (e + g));
                found = true;
            }
            if (!found) {
                e = dist(x1, y1, 0, n);
                g = dist(x2, y2, 0, n);
                if (e == (int) e && g == (int) g) {
                    out.println((int) (e + g));
                    found = true;
                }
            }
            if (!found) {
                e = dist(x1, y1, n, 0);
                g = dist(x2, y2, n, 0);
                if (e == (int) e && g == (int) g) {
                    out.println((int) (e + g));
                    found = true;
                }
            }
            if (!found) {
                e = dist(x1, y1, n, n);
                g = dist(x2, y2, n, n);
                if (e == (int) e && g == (int) g) {
                    out.println((int) (e + g));
                    found = true;
                }
            }

            if (!found) {
                //System.out.println("HE HE");
                int a = getIndex(x1, y1, n);
                int b = getIndex(x2, y2, n);
               
                int p, q, r, s;
                if (a == 0 || b == 0) {
                  //  System.out.println("HE HE");
                    p = n - y1;
                    r = n - y2;
                    q = y1;
                    s = y2;

                } else {
                   //  System.out.println(a + " " + b);
                    p = n - x1;
                    r = n - x2;
                    q = x1;
                    s = x2;
                }
               // System.out.println((p + r) + " " + (q + s));
                out.println(Math.min(p + r + n, q + s + n));
            }




        }
        out.close();
    }

    public static double dist(int x1, int y1, int x2, int y2) {
        double val = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
        return Math.sqrt(val);
    }

    /**
     * Four cases:
     *
     * 0,0 -> 0,n : 0 0,n -> n,n : 1 n,n -> n,0 : 2 n,0 -> 0,0 : 3
     */
    public static int getIndex(int x, int y, int n) {
        if (x == 0) {
            return 0;
        } else if (x == n) {
            return 2;
        } else if (y == n) {
            return 1;
        } else {
            return 3;
        }
    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    static int pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        int val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val;
        } else {
            return val * val * a;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
    static Point minus(Point a, Point b) {
        return new Point(a.x - b.x, a.y - b.y);
    }

    static Point add(Point a, Point b) {
        return new Point(a.x + b.x, a.y + b.y);
    }

    static double cross(Point a, Point b) {
        return a.x * b.y - a.y * b.x;
    }

    static class Point {

        int x, y;

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

        @Override
        public String toString() {
            return "Point: " + x + " " + y;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {


            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}