There are some hats in a box. 1/6 of them are red, 1/3 of blue, and 3/7 of the remainder are green. If there are 27 green hats, how many hats are there altogether