#K77957. Longest Snake
Longest Snake
Longest Snake
In this problem, you are given a grid of size (n \times m). Each cell in the grid contains one of the following characters: '.' (an empty cell), 'S' (the starting position of the snake), or 'F' (a cell containing food). The snake starts at the cell marked with 'S' and can move in four directions: up, down, left, or right. It cannot revisit any cell that it has already visited. When the snake moves into a cell with food ('F'), it consumes the food and its length increases by 1. Moving into an empty cell ('.') does not change the snake's length. Your task is to calculate the maximum possible length of the snake, starting with an initial length of 1, that can be achieved by consuming the food while traversing the grid without revisiting any cells.
inputFormat
The first line of input contains two integers (n) and (m) ((1 \leq n, m \leq 10)) representing the number of rows and columns of the grid. The following (n) lines each contain a string of length (m) that represents a row of the grid. It is guaranteed that there is exactly one 'S' in the grid.
outputFormat
Output a single integer which is the maximum length of the snake that can be achieved.## sample
3 3
..F
S..
...
2