Image -> Mode -> Indexed”, select “Generate optimum palette”, and set the Maximum number of colours to 256.