MaxSum (Happy Sum - 2)#5861

MaxSum (Happy Sum - 2)

4 seconds
64 megabytes
Very easy

You have a rectangular table with rows and columns. Each cell contains a non-negative integer. You can traverse this table from top to bottom, starting from any cell in the top row. From a cell at position , you can move to one of the "lower neighboring" cells: (i+1, j-1), (i+1, j), or (i+1, j+1). Note that if j = M, you cannot move to (i+1, j+1), and if j = 1, you cannot move to (i+1, j-1). You can finish your path in any cell of the bottom row.

Write a program that finds the maximum possible lucky sum of the values in the cells traversed along any valid path. A lucky number is a positive integer whose decimal representation contains only the digits and . For example, , , and are lucky numbers; , , , and are not. It is important that the sum itself is a lucky number, not the individual addends.

Input

The first line contains two integers, and (1 \leq N, M \leq 12), the number of rows and columns. Each of the following lines contains space-separated non-negative integers, each with at most decimal digits, representing the table cells.

Output

Output the largest possible lucky sum among all valid paths, or impossible (without quotes, lowercase Latin letters) if no such path has a lucky sum.

Examples

Example 1

Loading
Loading