This page is still under construction.

Parts of this page are still being built. What you see may change.

Robot

Time limit1sMemory limit128 MB

Summary
Write the shortest down-right program of at most k steps whose repetition exits the board without hitting an obstacle, ties broken lexicographically.
Level

Hard8 of 10

Topics
Dynamic programming, Math, Greedy
Solved
No attempts yet

Problem

A child received a programmable robot as a gift. The robot can store a program, which is a sequence of at most kk moves. When it is turned on, the robot performs the moves of the program one after another. After finishing the last move it returns to the start of the program and repeats the whole sequence again, looping forever.

The robot is placed on the top-left square of an n×nn \times n board. Some of the other squares hold obstacles that the robot may not enter. Your task is to write a program for the robot so that, by repeating it, the robot eventually walks off the board.

Only two kinds of moves are allowed: step one square down, or step one square to the right. In the program the character '1' means a step down and the character '0' means a step to the right. The robot walks off the board as soon as a move would take it past the bottom edge or past the right edge. The robot must never step onto an obstacle.

Input

The first line contains two integers nn and kk (1≤n≤10001 \le n \le 1000, 1≤k≤501 \le k \le 50), where nn is the side length of the board.

Each of the next nn lines contains a string of nn characters describing one row of the board. The character 'R' marks the robot's starting square, which is always the top-left corner. The character '.' marks a free square, and the character 'X' marks a square that holds an obstacle.

You may assume that a program of length at most kk that lets the robot leave the board always exists.

Output

Print a single line: the program as a string of at most kk characters, where '0' is a step to the right and '1' is a step down.

If more than one program works, print the shortest one. If more than one shortest program works, print the lexicographically smallest among the shortest.

Examples3

  1. Example 1

    Input
    6 4
    R.X...
    X...XX
    XXX...
    X..XX.
    XX.X.X
    ..X...
    
    Expected output
    010
    
  2. Example 2

    Input
    1 1
    R
    
    Expected output
    0
    
  3. Example 3

    Input
    2 2
    RX
    ..
    
    Expected output
    1