Under construction

Still being built. Things may change

Fastest Thing Alive

Interview

Time limit2sMemory limit2048 MB

Summary
Find a route from a blank cell in the first row to a blank cell in the last row, moving down one row per step and shifting at most one lane left or right.
Level

Medium4 of 10

Topics
Dynamic programming, Matrix
Solved
No attempts yet

Problem

The villainous Doctor Pearman (some prefer to call him Dr. Mechanic) is up to no good again. With his newest machine, he has cracked the surface of the earth to tap into the ancient power hidden below and use it to rule the world. After seeing this, the hero Shonic sets out at once along Dragon Road to reach the Doctor and stop his plan.

Along the road, Shonic comes across a spikefield of nn rows divided into mm lanes. Each space in the spikefield is either a spike trap or blank. Shonic has no magic rings left, so one touch of a spike kills him and the Doctor's plan succeeds. He must pass through a blank field in every row. He moves very fast, so he can make only one horizontal move when he goes to the next row. He can go left and move down one row, go right and move down one row, or stay in the same lane and move down one row. He cannot leave the spikefield, so he cannot move left from the leftmost lane. When he enters the spikefield, he can choose the starting field in the first row, but that field must be blank. A successful route takes him through every row, starting in the first row and ending on a blank field in the last row. Help Shonic find a way to the end of the spikefield.

Input

The first line contains two integers nn (2≤n≤1032 \leq n \leq 10^3) and mm (2≤m≤1032 \leq m \leq 10^3), the number of rows and the number of columns in the spikefield.

The next nn lines each contain a string of length mm that describes the spikefield. A * (asterisk) marks a spike trap. A _ (underscore) marks a blank field that Shonic can cross.

Output

Print either of the following.

A single integer ll (1≤l≤n1 \leq l \leq n), the lane where Shonic starts.

A string of n−1n - 1 characters, each L, R, or F, for left, right, and forward. This is the sequence of moves that takes Shonic to the end of the spikefield without touching a spike.

If no valid path exists, print impossible.

If several solutions exist, print any one of them.

Examples2

  1. Example 1

    Input
    5 5
    _*_**
    __*__
    ***__
    **_**
    **_**
    
    Expected output
    3
    RFLF
    
  2. Example 2

    Input
    5 5
    _*_**
    __*__
    ***__
    **_**
    ****_
    
    Expected output
    impossible