import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int all = 12 * 60 * 60; TreeSet sames = new TreeSet<>(); for (int i = 1; i <= 11; i++) { sames.add(all * i / 11); sames.add(all * i / 11 + all); } int second = a * 3600 + b * 60; System.out.println(sames.ceiling(second) - second); } }