using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static long NN => long.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (h, m) = (c[0], c[1]); var dh = (60 * h + m) * 60 % 43200; var dm = 43200 / 60 * m; var time = 0; while (true) { var ndh = dh + 1; var ndm = dm + 12; if (dh == dm || (dh > dm && ndh < ndm)) { WriteLine(time); return; } ++time; dh = ndh % 43200; dm = ndm % 43200; } } }