Function to find valid positions for the pipeline stages