1-2 mg of Melatonin ~20min before you wish to fall asleep
Alternatively, according to Eliezer’s experience, it could be taken much more than 20 minutes in advance. I take .3mg about 3 hours before sleeping.
In my experience small doses regulate the sleep schedule whereas bigger doses have a mild sedative effect. I take 0.25mg 1-3 hours before going to sleep and 1-3mg straight before going to bed for staying asleep.