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
//package de.skysoldier.tests;

import java.util.Scanner;

public class ArtursAufgabe {
	
	public static int calculateMinPath(int n, int x1, int y1, int x2, int y2) {
		// both left or both right
		if(x1 == 0 && x2 == 0 || x1 == n && x2 == n) {
			return (int) Math.abs(y2 - y1);
		}
		// both top or both bottom
		if(y1 == 0 && y2 == 0 || y1 == n && y2 == n) {
			return (int) Math.abs(x2 - x1);
		}
		// one left one right
		if(x1 == 0 && x2 == n || x1 == n && x2 == 0) {
			return n + (int) Math.min(y1 + y2, n - y1 + n - y2);
		}
		// one top one bottom
		if(y1 == 0 && y2 == n || y1 == n && y2 == 0) {
			return n + (int) Math.min(x1 + x2, n - x1 + n - x2);
		}
		// one left one top
		if(x1 == 0 && y2 == n) {
			return (n - y1) + x2;
		}
		if(x2 == 0 && y1 == n) {
			return (n - y2) + x1;
		}
		// one top one right
		if(y1 == n && x2 == n) {
			return (n - x1) + (n - y2);
		}
		if(y2 == n && x1 == n) {
			return (n - x2) + (n - y1);
		}
		// one right one bottom
		if(x1 == n && y2 == 0) {
			return y1 + (n - x2); 
		}
		if(x2 == n && y1 == 0) {
			return y2 + (n - x1);
		}
		// one bottom one left
		if(y1 == 0 && x2 == 0) {
			return x1 + y2;
		}
		if(y2 == 0 && x1 == 0) {
			return x2 + y1;
		}
		return 0;
	}
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int minPath = calculateMinPath(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());
		System.out.println(minPath);
		
//		System.out.println(calculateMinPath(10, 0, 5, 10, 3));
//		JFrame frame = new JFrame();
//		frame.setSize(800, 800);
//		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		
//		int size = 11;
//		
//		JPanel content = new JPanel();
//		content.setLayout(new GridLayout(size, size));
//		
//		for(int i = 0; i < size; i++) {
//			for(int j = 0; j < size; j++) {
//				TestButton button = new TestButton("(" + j + ", " + i + ")");
//				button.setForeground(Color.WHITE);
//				button.setBackground(i == 0 || j == 0 || i == size - 1 || j == size - 1 ? Color.BLACK : Color.GRAY);
//				button.x = j;
//				button.y = i;
//				button.addActionListener(new ActionListener() {
//					@Override
//					public void actionPerformed(ActionEvent e) {
//						if(button1 == null) {
//							button1 = (TestButton) e.getSource();
//							button1.setBackground(Color.RED);
//						}
//						else if(button2 == null) {
//							button2 = (TestButton) e.getSource();
//							button2.setBackground(Color.RED);
//							
//							System.out.println("cMP(" + (size - 1) + ", " + button1.x + ", " + button1.y + ", " + button2.x + ", " + button2.y + ") = " + calculateMinPath(size - 1, button1.x, button1.y, button2.x, button2.y));
//							button1.setBackground(Color.BLACK);
//							button2.setBackground(Color.BLACK);
//							button1 = null;
//							button2 = null;
//						}
//					}
//				});
//				content.add(button);
//			}
//		}
//		
//		frame.add(content);
//		
//		frame.setVisible(true);
	}

//	static TestButton button1 = null;
//	static TestButton button2 = null;
//	static class TestButton extends JButton {
//		public int x, y;
//		
//		public TestButton(String label) {
//			super(label);
//		}
//	}
}
