Under construction

Still being built. Things may change

Smooth numbers

Interview

Time limit2sMemory limit1024 MB

Summary
Given a digit count l (1 to 100), find the largest l-digit number whose interior digits are each less than the average of their neighbors, or report -1.
Level

Medium5 of 10

Topics
Math, Greedy, Brute force
Solved
No attempts yet

Problem

A positive integer is called smooth if each of its digits except the first and the last is less than the average of its two neighboring digits. That is, if x=an⋅10n+an−1⋅10n−1+⋯+a1⋅10+a0x = a_n \cdot 10^n + a_{n-1} \cdot 10^{n-1} + \cdots + a_1 \cdot 10 + a_0, then ai<ai−1+ai+12a_i < \frac{a_{i-1} + a_{i+1}}{2} for every ii with 1≤i≤n−11 \le i \le n-1.

Vasya has studied smooth numbers for a long time. He wants to know whether a smooth number with exactly ll digits exists and, if one does, what the greatest such number is. Help Vasya find the greatest ll-digit smooth number.

Input

The input file contains one integer ll (1≤l≤1001 \le l \le 100), the number of digits in the smooth number.

Output

Print the greatest ll-digit smooth number, or −1-1 if no such number exists.

Examples1

  1. Example 1

    Input
    3
    
    Expected output
    989