instr = input() instr_str = instr.split(" ") short_t = int(instr_str[0]) long_t = int(instr_str[1]) total = int(short_t*3600 + long_t*60) count = 0 result= 0 while count < 22: if total == int(43200*count/11): result = 0 elif total > int(43200*count/11) and total < int(43200*(count+1)/11): result = (int(43200*(count+1)/11) -total) count = count+1 print(result)