Largest Prime Substring

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a string consisting only of digits. Write a program that, among all contiguous substrings of the string interpreted as integers, finds the one that is prime and has the largest value.

In this problem, a number is considered prime only if it is a prime between $2$ and $100{,}000$ inclusive.

Input

The input consists of several test cases. The number of test cases does not exceed $1{,}000$.

Each test case is given on its own line as a digit string whose length does not exceed $255$. The last line of the input contains a single $0$, which marks the end of the input.

Only inputs in which at least one substring is prime are given.

Output

For each test case, print on its own line the largest-valued prime substring.