import sys
def affine(a, b, x):
	return (a*x + b) % 26

a = int(sys.argv[1]) #first command line arg
b = int(sys.argv[2]) #second command line arg
orig = 1
count = 0

x = affine(a, b, orig)
count += 1

while True:
	x = affine(a, b, x)
	if orig is x:
		break
	count += 1

print(count)