This problem can be solved by pre-school children in 5-10 minutes. By programmers in one hour. By people with a higher education… Well, check it out yourself and post the answer in the comments when you have solved it. Now, those who want to solve it, do not cheat to see if anyone has posted the answer. But then, posting just the answer does not explain the logic here.
This took me just few minutes, so I guess I have a pre-school mentality….