Complex conditions on a path can be difficult to express in cypher. If the criterion is as simple as in your abstraction, you can collect the 'N' nodes and filter your matched 'M' nodes with ALL
and a path predicate.
With a graph like
(:N)<--(m1:M)-->(:N)<--(m2:M)
you want to return (m1)
but not (m2)
, correct? Try
MATCH (n:N)
WITH collect(n) AS nn
MATCH (m:M)
WHERE ALL (n IN nn
WHERE n--m)
RETURN m
See console: http://console.neo4j.org/?id=cqrrpe