Four people are shipwrecked and there are only coconuts to eat. Being prudent they collect all the coconuts they can find and weary from their work fall asleep.

In the night one of the castaways wakes up and secretly divides the coconuts into four equal piles, she hides her share and throws to the monkeys the three that were left over before putting all the remaining nuts back into one pile.

Later another of the castaways wakes up and she too secretly divides the coconuts into four equal piles, she hides her share and throws to the monkeys the three that were left over before putting all the remaining nuts back into one pile.

Later still, yet another of the castaways wakes up and she too secretly divides the coconuts into four equal piles, hides her share and throws to the monkeys the three that were left over before putting all the remaining nuts back into one pile.

Just before morning the last castaway wakes up and she too secretly divides the coconuts into four equal piles, hides her share and throws to the monkeys the three that were left over before putting all the remaining nuts back into one pile.

Next morning with a much reduced pile the four castaways find they can share out equally all the coconuts that are left!

What is the least number of coconuts they could have started with?

**Extension:** Solve the generalised problem with n castaways, dividing the pile into n shares, hiding one share and throwing m coconuts to the monkeys each time.