import java.util.Scanner;
class Main {
public static void main
(String[] args
) { int counter = 1;
Scanner in
= new Scanner
(System.
in); int quantity = in.nextInt();
int instrument = in.nextInt();
if ((quantity == 6 && instrument != 1) || (quantity == instrument && quantity % 2 == 0)) {
} else if (quantity == instrument) {
for (int num = 1; num % quantity != 0; num += 6) {
if (num != 1 && num % quantity == 1){
} else {
counter++;
}
}
} else {
for (int num = 1; num % quantity != instrument; num += 6) {
if (num != 1 && num % quantity == 1) {
} else {
counter++;
}
}
}
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwogCmNsYXNzIE1haW4gewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHsKCQlpbnQgY291bnRlciA9IDE7CgkJU2Nhbm5lciBpbiA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CgkJaW50IHF1YW50aXR5ID0gaW4ubmV4dEludCgpOwoJCWludCBpbnN0cnVtZW50ID0gaW4ubmV4dEludCgpOwoJCWlmICgocXVhbnRpdHkgPT0gNiAmJiBpbnN0cnVtZW50ICE9IDEpIHx8IChxdWFudGl0eSA9PSBpbnN0cnVtZW50ICYmIHF1YW50aXR5ICUgMiA9PSAwKSkgewoJCQlTeXN0ZW0ub3V0LnByaW50KDApOwoJCX0gZWxzZSBpZiAocXVhbnRpdHkgPT0gaW5zdHJ1bWVudCkgewoJCQlmb3IgKGludCBudW0gPSAxOyBudW0gJSBxdWFudGl0eSAhPSAwOyBudW0gKz0gNikgewoJCQkJaWYgKG51bSAhPSAxICYmIG51bSAlIHF1YW50aXR5ID09IDEpewoJCQkJCVN5c3RlbS5vdXQucHJpbnQoMCk7CgkJCQkJU3lzdGVtLmV4aXQoMCk7CgkJCQl9IGVsc2UgewoJCQkJCWNvdW50ZXIrKzsKCQkJCX0KCQkJfQoJCQlTeXN0ZW0ub3V0LnByaW50KGNvdW50ZXIpOwoJCX0gZWxzZSB7CgkJCWZvciAoaW50IG51bSA9IDE7IG51bSAlIHF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