import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]); int b = Integer.parseInt(sa[1]); br.close(); a %= 12; int x = 60 * 60 * 12; int[] y = new int[12]; for (int i = 0; i < 12; i++) { y[i] = x * i / 11; } int ans = Integer.MAX_VALUE; int t = 3600 * a + 60 * b; for (int i = 0; i < 12; i++) { int d = y[i] - t; if (d >= 0) { ans = Math.min(ans, d); } } System.out.println(ans); } }