Under construction

Still being built. Things may change

Telephone Numbers

Time limit1sMemory limit1024 MB

Summary
Given a list of numbers, the task finds the smallest one whose digits are all equal or strictly increasing, or prints NERASTA if none exists.
Level

Easy2 of 10

Topics
Implementation, Sorting
Solved
No attempts yet

Problem

Vilius is starting a business that delivers pictures to homes. He only needs to choose and buy an easy-to-remember phone number. Vilius has a list of phone numbers that he can buy.

He considers a number memorable only if all of its digits are equal (for example, 2222), or if its digits strictly increase (for example, 23679).

Find a memorable number in the given list.

Input

The first line contains the number of phone numbers, N. Each of the next N lines contains one distinct positive integer K.

Output

Print one memorable number. If the list has several memorable numbers, print the smallest one. If the list has no memorable numbers, print NERASTA.

Constraints

1 ≤ N ≤ 1 000

1 ≤ K ≤ 100 000

Examples3

  1. Example 1

    Input
    5
    11111
    1111
    111
    43
    22
    
    Expected output
    22
    
  2. Example 2

    Input
    1
    4
    
    Expected output
    4
    
  3. Example 3

    Input
    6
    44
    33
    13
    59
    99
    10
    
    Expected output
    13