import java.util.HashSet;
import java.util.Objects;

public class Euler891 {
    static final long kCycleSeconds = 43200;

    static class GCDResult {
        long g, x, y;

        GCDResult(long g, long x, long y) {
            this.g = g;
            this.x = x;
            this.y = y;
        }
    }

    static GCDResult extendedGCD(long a, long b) {
        if (b == 0) {
            return new GCDResult(a, 1, 0);
        }
        GCDResult res = extendedGCD(b, a % b);
        long x = res.y;
        long y = res.x - (a / b) * res.y;
        return new GCDResult(res.g, x, y);
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static class Fraction {
        long num, den;

        Fraction(long num, long den) {
            this.num = num;
            this.den = den;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Fraction fraction = (Fraction) o;
            return num == fraction.num && den == fraction.den;
        }

        @Override
        public int hashCode() {
            return Objects.hash(num, den);
        }
    }

    public static String solve() {
        long[] speeds = { 1, 12, 720 };
        int[][] permutations = {
                { 0, 2, 1 }, { 1, 0, 2 }, { 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 }
        };

        HashSet<Fraction> moments = new HashSet<>();

        for (int[] idx : permutations) {
            long pa = speeds[idx[0]];
            long pb = speeds[idx[1]];
            long pc = speeds[idx[2]];

            long A = pb - pa;
            long B = pc - pa;
            long det = 719 * A - 11 * B;
            if (det == 0)
                continue;

            long D = Math.abs(det);
            long absA = Math.abs(A);
            long absB = Math.abs(B);

            GCDResult res = extendedGCD(absB, absA);
            long u = res.x * (B < 0 ? -1 : 1);
            long v = res.y * (A < 0 ? -1 : 1);

            long C = (11 * v + 719 * u) % D;
            if (C < 0)
                C += D;

            long g1 = gcd(kCycleSeconds, D);
            long numBase = kCycleSeconds / g1;
            long denBase = D / g1;

            for (long n = 0; n < D; ++n) {
                long n2 = (n * C) % D;
                if (n2 == n)
                    continue;

                long g2 = gcd(n, denBase);
                long num = numBase * (n / g2);
                long den = denBase / g2;
                moments.add(new Fraction(num, den));
            }
        }

        return Integer.toString(moments.size());
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
