- Time limit: 1.00 s
- Memory limit: 512 MB
You are given an grid whose each square contains a letter.
You should move from the upper-left square to the lower-right square. You can only move right or down.
What is the lexicographically minimal string you can construct?
Input
The first line has an integer : the size of the grid.
After this, there are lines that describe the grid. Each line has letters between A
and Z
.
Output
Print the lexicographically minimal string.
Constraints
Example
Input:
4 AACA BABC ABDA AACA
Output:
AAABACA