Make invalid trajectories return -1