// Arup Guha
// 10/22/2016
// Solution to 2016 NCPC Problem J: Jumbled Compass
// Solved during UCF practice teaming with Travis Meade.

import java.util.Scanner;

public class j {
	public static void main(String[] Args) {
		
		// Get input and difference.
		Scanner stdin = new Scanner(System.in);
		int a = stdin.nextInt();
		int b = stdin.nextInt();
		int diff = b - a;
		
		// First case.
		if (diff >= -179 && diff <= 180)
			System.out.println(diff);
			
		// Second case.
		else if (diff > 180)
			System.out.println(-360+diff);
		
		// Crazy negative case.
		else 
			System.out.println(360+diff);
	}
}
