Under construction

Still being built. Things may change

Robot

Time limit1sMemory limit1024 MB

Summary
Find the most cells a robot can clean on a grid, moving straight until blocked, turning right each time, from any free start and direction.
Level

Medium6 of 10

Topics
Simulation, Graph, Matrix
Solved
No attempts yet

Problem

Romas does not like cleaning, so he bought an autonomous robotic vacuum cleaner. The robot is quite primitive, though. While cleaning, it moves straight forward until it hits an obstacle (such as a piece of furniture or a wall). Then it turns right by 90 degrees and repeats the same motion.

Romas's flat plan can be modelled as an N×MN \times M grid. Each cell is either a free area that the robot can clean or an occupied cell that contains an obstacle. The robot moves parallel to the sides of the grid.

Romas switches the robot on before he leaves for work. He wants the largest possible area to be cleaned when he arrives.

The robot can be started from any free cell in any direction: up, down, left, or right. Find the largest area the robot can clean.

Input

The first line contains two integers NN and MM, the dimensions of the flat. The next NN lines describe the flat plan. Each line contains MM characters. . marks a free cell and # marks an occupied cell. All border cells are occupied, and there is at least one free cell.

Output

Print a single integer: the largest number of cells the robot can clean.

Constraints

3≤N,M≤10003 \le N, M \le 1000

Examples1

  1. Example 1

    Input
    5 6
    ######
    ###..#
    #...##
    #.##.#
    ######
    
    Expected output
    4