a, b = gets.split.map(&:to_i) cands = 12.times.map { |i| i * 12 * 60 * 60 / 11 } cands.push(12 * 60 * 60) t = (a % 12) * 60 * 60 + b * 60 puts cands.bsearch { |x| x >= t } - t