I present a method to allocate a given number of vaccines to members of a population who differ in their susceptibility to the disease so that the final size of the epidemic is minimised. I consider an arbitrary distribution of protection that the vaccine confers, including the extreme cases of leaky and all-or-none vaccines. The optimal vaccination policy depends on the distribution of protection. While for low values of the basic reproduction number R0 the optimal policy prioritises the most susceptible hosts, I show that for almost any distribution there is a threshold value of R0 above which the order of priority reverses and the least susceptible hosts should be vaccinated. The exception where this does not happen is the all-or-none vaccine. However, even a small deviation from the ideal all-or-none distribution can imply that the limited number of vaccines should be given to less susceptible hosts already at realistic values of R0.