So it's a directed graph, but not acyclic.
You could use subgraphNodes() from APOC path expanders, but you would need to pre-match to leaf nodes first, collect() them and use them as end nodes, and use a
limit:1 so that it stops looking after a single path to a leaf node is identified.
Alternately, if using Neo4j 4.x, you can use subqueries to limit the expansion to only one leaf node:
WHERE NOT (b)-[:ORIGID]->()
RETURN a.name as aName, b.name as bName
ORDER BY aName
That will find only one leaf node per a node. It won't look for others.
The LIMIT can't be dynamic from a variable, but if you executed a query prior to this to find the number of leaf nodes (
MATCH (a:Ident) WHERE NOT (a)-[:ORGID]->() RETURN count(a) ), and you passed that value as a parameter to your query, then you could use
RETURN DISTINCT b LIMIT $leafNodeCount so it would stop searching when all leaf nodes have been found.