// Arup Guha
// 11/1/2011
// Solution to 2011 South East Regional Problem D: Vive la Difference!

import java.util.*;

public class d {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int[] nums = new int[4];

		// Get first set of numbers.
		for (int i=0; i<nums.length; i++)
			nums[i] = stdin.nextInt();

		while (!allZeros(nums)) {

			int steps = 0;

			// Simulate steps and count them.
			while (!allEqual(nums)) {
				advance(nums);
				steps++;
			}

			System.out.println(steps);

			// Get next case.
			for (int i=0; i<nums.length; i++)
				nums[i] = stdin.nextInt();
		}


	}

	// Advances one step in the algorithm.
	public static void advance(int[] nums) {

		int[] ans = new int[nums.length];

		// Take the difference of each consecutive term, with wraparound.
		for (int i=0; i<nums.length; i++)
			ans[i] = Math.abs(nums[i] - nums[(i+1)%nums.length]);

		for (int i=0; i<nums.length; i++)
			nums[i] = ans[i];
	}

	// Returns true iff all items in nums are the same.
	public static boolean allEqual(int[] nums) {

		int i;
		for (i=1; i<nums.length; i++)
			if (nums[i] != nums[0])
				return false;
		return true;
	}

	// Returns true iff all the elements of nums equal 0.
	public static boolean allZeros(int[] nums) {

		for (int i=0; i<nums.length; i++)
			if (nums[i] != 0)
				return false;
		return true;
	}
}