#K38692. Extract Maximum Number from a String

    ID: 26255 Type: Default 1000ms 256MiB

Extract Maximum Number from a String

Extract Maximum Number from a String

Given an alphanumeric string S, your task is to extract all contiguous sequences of digits from S and output the maximum numeric value. If the string contains no digits, output -1.

For example, if the input is abc123xyz456def, the maximum extracted number is 456. If the input is abcdef, output -1 because there are no numbers.

The problem can be formalized as follows:

Let \( S \) be a string. Find all substrings \( s_i \) that match the regular expression \(\d+\) and let \( n_i \) be the integer value of \( s_i \). If there exists at least one \( n_i \), output \( \max_i \{ n_i \} \); otherwise, output \( -1 \).

inputFormat

The input is provided via standard input (stdin) and consists of a single line containing the string S.

outputFormat

Output the maximum numeric value found in the string. If no numbers exist in the string, output -1. The output should be written to standard output (stdout).

## sample
abc123
123