import qualified Data.Set as Set
main=map read.words<$>getLine>>=print.(\n->max(n-1)0).(\s->length(Set.toList s)).(\l->(Set.intersection(Set.fromList[((l!!0)::Int)..(l!!1)])(Set.fromList[(l!!2)..(l!!3)])))