Factory Refirbishment (1/2 Points)


You are trying to refirbish a factory for your own use.

The factor has an n×mn \times m grid of conveyors. Each conveyor has a set direction. If an object is placed on top of it, the conveyor will move that object in its set direction.

You want to rearrange the conveyors such that the an object placed on the top left conveyor will eventually reach the bottom right conveyor. To do this, you can rotate any conveyor 90∘90^\circ, for a cost of $1\$1.

What is the minimum cost to rearrange the conveyors in this way?

Input

The first line contains integers n,mn,m, representing the dimension conveyor grid.

The following nn lines contain mm space separated characters. These will be either U, D, L or R, representing the initial direction of each conveyor.

Output

An integer containing the minimum cost to rearrange the conveyors such that an object placed on the top left will reach the bottom right.

Constraints

  • 1≤n,m1 \le n,m
  • 1≤n×m≤2×1061 \le n \times m \le 2 \times 10^6

Subtask 1 - 1 Point

  • n=1n = 1

Subtask 2 - 1 Point

  • No additional constraints

Example - Subtask 1

Input
Input 1
1 5
R R D L D 
Input 2
3

Example - Subtask 2

Input 3
5 5
R R L U R 
D L D L R 
D L L R R 
U R D U R 
L D L D D 
Output 1
5

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.