While there is a strong focus on the negative consequences of maternal immune activation (MIA) on the developing brain, very little attention is directed towards potential advantages of early life challenges. In this study we utilized a polyinosine-polycytidylic acid (poly(I:C)) MIA model to test visual discrimination (VD) and reversal learning (RL) in mice using touchscreen technology. Significant sex differences emerged in that MIA improved the latency for males to make a correct choice in the VD task while females reached criterion sooner, made fewer errors and utilized fewer correction trials in RL compared to saline-treated controls. These surprising improvements were accompanied by the sex-specific upregulation of several neural markers critical to cognitive functioning (e.g., Gabrg2, Grin1, Grin2b, Htr2a, Chrm1, Prkca, and Camk2a mRNA in prefrontal cortex (PFC)), indicative of compensatory plasticity in response to the MIA challenge. In contrast, when exposed to a "two-hit" stress model (MIA combined with loss of the social component of environmental enrichment (EE)), mice showed no evidence of anhedonia but required an increased number of PD and RL correction trials. These animals also had significant reductions of CamK2a mRNA in the PFC. Appropriate functioning of synaptic plasticity, via mediators such as this protein kinase and others, are critical for behavioral flexibility. Although EE has been implicated in delaying the appearance of symptoms associated with certain brain disorders, these findings are in line with evidence that it also makes individuals more vulnerable to its loss. Overall, with the right "dose", early life stress exposure can confer at least some functional advantages, which are lost when the number or magnitude of these exposures become too great.