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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Tree {
   
    public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) 
    { 
        
        List<Map.Entry<Integer, Integer> > list = 
               new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); 
  
      
        Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { 
            public int compare(Map.Entry<Integer, Integer> o1,  
                               Map.Entry<Integer, Integer> o2) 
            { 
                return (o1.getValue()).compareTo(o2.getValue()); 
            } 
        }); 
          
       
        HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); 
        for (Map.Entry<Integer, Integer> aa : list) { 
            temp.put(aa.getKey(), aa.getValue()); 
        } 
        return temp; 
    } 
    static class InputReader {
 
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
 
		public InputReader(InputStream st) {
			this.stream = st;
		}
 
		public int read() {
			if (snumChars == -1)
	 			throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}
 
		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
 
	}
    static PrintWriter w = new PrintWriter(System.out);
    static int parent[];
    public static int find(int parent[],int i){
        if(parent[i]==-1)
            return i;
        return find(parent,parent[i]);
    }
    public static void union(int parent[],int x,int y){
        int xset=find(parent,x);
        int yset=find(parent,y);
        parent[xset]=yset;
    }
    static  HashMap<String,Character> map;
    static int color[][];
    //static ArrayList<Integer> arr[];
    static long mod=1000000007;
    public static int bfs(ArrayList<Integer> arr[],boolean visited[],int count,int i){
         
        Queue<Integer> q=new LinkedList();
        q.add(i);
        while(!q.isEmpty()){
            int j=q.poll();
            if(visited[j])
                continue;
            else{
                visited[j]=true;
                 count++;
                 
                 Iterator itr=arr[j].iterator();
                 while(itr.hasNext()){
                     int a=(int)itr.next();
                     if(!visited[a])
                        q.add(a);
                 }
            }
        }
       return count;     
    } 
    
    static int min=Integer.MAX_VALUE;
    public static void dfs(int i,int j,int rs,int cs,int rt,int ct,boolean found,int arr[][],int n,int pr,int pc,boolean start,boolean end,int r2,int c2,boolean visited[][]){
        
    }
    public static void main(String[] args) {
         InputReader sc=new InputReader(System.in);
       
        int n=sc.ni();
        int x1=sc.ni();
        int y1=sc.ni();
        int x2=sc.ni();
        int y2=sc.ni();
        int x=0,y=0;
        if(Math.abs(y2-y1)==n){
            y=n;
            x=Math.min(x1+x2,Math.abs(n-x1)+Math.abs(n-x2));
        }
        else if(Math.abs(x2-x1)==n){
            x=n;
            y=Math.min(y1+y2,Math.abs(n-y1)+Math.abs(n-y2));
        }
       
        else{
            x=Math.abs(x2-x1);
            y=Math.abs(y2-y1);
        }
        w.println(x+y);
        w.close();
    }
}
