This page is still under construction.

Parts of this page are still being built. What you see may change.

Cute Common Divisor

Interview

Time limit2sMemory limit512 MB

Summary
Given a and b up to 1e9, find a common divisor d whose digit sum is as large as possible, and print any such divisor.
Level

Medium6 of 10

Topics
Number theory, Math, Brute force, Implementation
Solved
No attempts yet

Problem

Vasya is very good at counting crows outside the window during math class. Today was an unusual day, since there were a lot of crows. On top of that, there were two kinds: white and black. By the middle of the lesson Vasya finished counting, and outside the window there were aa white crows and bb black crows.

Since an unbearably long time remained until the end of the lesson, Vasya decided to listen to what the teacher was saying. At that moment the teacher was explaining what the greatest common divisor of two numbers is. Vasya is a very talented boy and understood it right away. He instantly computed the greatest common divisor of aa and bb.

After that he came up with a new term: cute common divisor. Vasya decided to call a positive integer dd a cute common divisor of xx and yy if xx is divisible by dd, yy is divisible by dd, and the sum of the digits of dd is maximal.

Help Vasya find the cute common divisor of aa and bb.

Input

The only line of the input file contains two integers aa, bb (1≤a,b≤1091 \le a, b \le 10^9).

Output

Print the cute common divisor of aa and bb on the only line of the output file. If there are several answers, you may print any of them.

Examples1

  1. Example 1

    Input
    220 440
    
    Expected output
    55