Prisons given two years to reduce overcrowding