South Africa bowled out for 313