Behavioural Flexibility and Collective Intelligence