LogiQuest

291. Count Regions of Same Colour

EasyDFSFlood Fill

The grid holds lowercase letters. Two cells belong to the same region if they have the same letter and are connected through up/down/left/right moves. Print the number of regions.

Input format

Line 1: r c Next r lines: strings of length c

Output format

The number of regions.

Example 1

Input

3 4
aabb
abbb
ccca

Output

4

Example 2

Input

1 1
z

Output

1

Constraints

1 ≤ r, c ≤ 500

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…