Moving Ball


You are given an n×mn \times m grid, each with a corresponding direction:

  • U - up
  • D - down
  • L - left
  • R - right

A ball is placed somewhere on the grid. Each second, the ball moves 1 place in the direction of its current cell.

What is the minimum number of cells you have to change, such that the ball will remain on the grid forever, no matter where the ball is initially placed.

Input

The first line contains integers n,mn,m, which denote the dimensions of the grid. The next nn lines contain mm characters, where the jj-th character on the ii-th line represents the direction of cell (i,j)(i, j).

Output

The total number of cells you need to change.

Constraints

  • 1≤n,m≤2001 \le n,m \le 200

Example 1

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

Example 2

Input 2
5 10
R L R U D R D L D R
L L D L L D R D L D
D R L L R D U R D D
R U L U R L L L U L
U U U D L D U L L D
Output 2
6

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.