Grid colouring game : Find the number of red and blue lines drawn

Problem Description: Walter has a grid of size N*M , initially each of the cell is white . Walter can draw a horizontal or vertical stroke which can be 1 or more cell long. Walter only draws horizontal stroke with RED colour and Vertical stroke with BLUE color Walter never draws two horizontal or two vertical stroke overlapping. If a horizontal stroke crosses vertical stroke then color of the cell is Green. Given the string having the color patter of cells , find the number of red and blue strokes required to achieve it .