PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000122. Xóa chữ số để tạo số nguyên tố (Prime Deletion)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xóa chữ số để tạo số nguyên tố (Prime Deletion)

Prime Deletion

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence containing the nine digits 11 through 99, each exactly once. You may delete digits from arbitrary positions, but may not delete when only two digits remain. The surviving digits must preserve their relative order.

Produce a remaining sequence representing a prime number. If multiple answers exist, any is accepted; print -1 if impossible.

Input

One line contains a length-nine string ss that is a permutation of digits 1 through 9.

Output

Print a subsequence of ss of length at least two, in original order, that represents a prime number; print -1 if impossible.

Subtasks

  • Subtask 1 (100 points): ∣s∣=9|s|=9; ss is a permutation of exactly the digits 1,2,3,4,5,6,7,8,91,2,3,4,5,6,7,8,9.

Examples

Input

987654321

Output

31

Explanation

In 987654321, digit 3 occurs before 1. Delete the digits 9,8,7,6,5,4,2, keeping the ordered subsequence 31. The number 3131 is prime (it has no prime divisor at most 31<6\sqrt{31}<6). Two digits remain, so the deletion rule is respected.