Given a $2018 \times 4$ grid, tint the cells with red and blue such that each row and each column has an equal number of red and blue cells. Determine the number of ways, $M$, to tint the grid with the mentioned requirement and find $M \pmod{2018}$.

Let's think step by step and output the final answer within \boxed{}.
user