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.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.text.StyledEditorKit.ItalicAction;

import static java.lang.Double.*;
import static java.lang.Integer.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main implements Runnable {
	
	private void solve() throws IOException {
//		long start = System.currentTimeMillis();
		readData();
		int[] d1 = processing(n, x1, y1);
		int[] d2 = processing(n, x2, y2);
		int ans = 1000000;
		if (x1 == x2 && (x1 == 0 || x1 == n)) {
			ans = min(ans, abs(y1 - y2));
		}
		if (y1 == y2 && (y1 == 0 || y1 == n)) {
			ans = min(ans, abs(x1-x2));
		}
		for (int i = 0; i < 4; ++i) {
			ans = min(ans, d1[i] + d2[i]);
		}
		println(ans);
	}
	
	private int[] processing(int n, int x, int y) {
		if (x == 0) {
			return new int[] {y, y + n, 2*n - y, n-y};
		}
		else if (x == n) {
			return new int[] {y + n, y, n-y, 2*n-y};
		}
		else if (y == 0) {
			return new int[] {x, n-x, 2*n - x, n+x};
		}
		else {
			return new int[] {x + n, 2*n - x, n-x, x};
		}
	}	
	
	private void readData() throws IOException {
		n = nextInt();
		x1 = nextInt();
		y1 = nextInt();
		x2 = nextInt();
		y2 = nextInt();
	}
	
	private int n;
	private int x1;
	private int y1;
	private int x2;
	private int y2;
	
	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}
	
	private void print(long value) {
		writer.print(value);
	}
	
	private void println(long value) {
		writer.println(value);
	}
	
	private void print(char ch) {
		writer.print(ch);
	}

	private void println(String s) {
		writer.println(s);
	}

	private void print(String s) {
		writer.print(s);
	}
	
	private void print(int value) {
		writer.print(value);
	}
	
	private void println(int value) {
		writer.println(value);
	}

	private void printf(String f, double d) {
		writer.printf(f, d);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}