#P3100. Ski Course Stamp

    ID: 16358 Type: Default 1000ms 256MiB

Ski Course Stamp

Ski Course Stamp

Farmer John is transforming his field into a ski course for the winter Moolympics. The field has dimensions \(M\times N\) (where \(1\le M,N\le 100\)) and the desired course design is given by an \(M\times N\) grid. Each cell in the grid is marked with either an 'R' (rough) or an 'S' (smooth), for example:

RSRSSS
RSRSSS
RSRSSS

Farmer John has modified his tractor so that it can stamp any \(B\times B\) block (with \(B\le M\) and \(B\le N\)) on the field with either all rough snow or all smooth snow. During the process, each cell must be stamped at least once (a cell can be stamped multiple times, and later stamps can override previous ones). However, when a stamp is applied, the entire \(B\times B\) block is painted with a single texture.

Thus, if a cell's final texture is, say, 'R', then there must exist at least one \(B\times B\) stamp covering that cell in which every square is 'R'. The challenge is to determine the largest possible \(B\) that allows Farmer John to achieve the target grid using these stamping operations.

Hint: For every cell, you need to verify that there exists some \(B\times B\) block (which covers that cell) that is uniformly filled with the same character as the cell's target texture.

inputFormat

The first line contains two integers \(M\) and \(N\), representing the number of rows and columns of the field.

Each of the next \(M\) lines contains a string of length \(N\) consisting of characters 'R' and 'S', which describe the desired snow texture for each cell.

outputFormat

Output a single integer \(B\) — the largest stamp size for which it is possible to cover the entire \(M\times N\) field with a sequence of \(B\times B\) stamping operations that result in the given design.

sample

3 6
RSRSSS
RSRSSS
RSRSSS
1

</p>