#!/usr/bin/env python2 import time import random import fractions n = list(raw_input()) d = int(''.join(n)) while time.clock() < 0.9: random.shuffle(n) x = int(''.join(n)) d = fractions.gcd(d, x) print(d)