eolymp
bolt
Try our new interface for solving problems
Problems

Divisible by 8

Divisible by 8

Given big integer n. Can you rearrange its digits so that the resulting number is divisible by 8? If there are multiple answers, print the smallest. Do not print the leading '0'.

Input

One big integer n (1 ≤ |n| ≤ 1000, where |n| denotes the number of digits in number n, n1)

Output

If the solution does not exist, print -1. Otherwise print the required minimum number.

Time limit 1 second
Memory limit 128 MiB
Input example #1
8
Output example #1
8
Input example #2
5
Output example #2
-1
Input example #3
24
Output example #3
24
Author Rashad Mammadov, Abutalib Namazov
Source Azərbaycan 2019: Yuxarı yaş olimpiada hazırlığı qrupuna seçim turu