find nearest common ancestor