// Arup Guha
// 6/25/2012
// Solution to 2008 Southeast Regional Problem E: Combination Lock

import java.util.*;

public class e {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int N = stdin.nextInt();
		int[] t = new int[3];
		for (int i=0; i<3; i++)
			t[i] = stdin.nextInt();

		// Go through each lock.
		while (N != 0) {

			System.out.println(solve(N, t));

			N = stdin.nextInt();
			for (int i=0; i<3; i++)
				t[i] = stdin.nextInt();
		}
	}

	public static int solve(int N, int[] t) {

		// Slowest way to get to t1.
		int tally = 3*N-1;

		// Go counterclockwise, back around to t1.
		tally += N;

		// Now, get to t2. In the wrap-around case, we just add N.
		if (t[0] > t[1])
			tally += (N - t[0] + t[1]);
		else
			tally += (t[1] - t[0]);

		// Finally, get to t3. Same wrap around case here.
		if (t[2] > t[1])
			tally += (N - t[2] + t[1]);
		else
			tally += (t[1] - t[2]);

		return tally;

	}

}