Four men were shipwrecked on an island. They didn't have any food with them, so they searched the island for food and found some pineapples. After they had gathered some pineapples, they decided to rest and they all fell asleep. The first man woke up and he was extremely hungry so he ate 1/3 of the pineapples. He then went back to sleep. The second man woke up and he was extremely hungry so he ate 1/3 of the pineapples. He then went back to sleep. The third man woke up and he was extremely hungry so he ate 1/3 of the pineapples. He then went back to sleep. The fourth man woke up and he was extremely hungry, but he ate only his rightful share of the remaining pineapples. There were 6 pineapples left.

How many pineapples did the men gather?