Answer: 19.
For 1≤i≤5, let ai denote the i-th girl and let Ai denote the set of students that ai knows. Similarly let bi denote the i-th boy and let Bi denote the set of students that bi knows.
Since ∣Ai∩B1∣=i−1, ∣Ai∩B5∣=5−i, we have
∣A1∣≥4, ∣A2∣≥3, ∣A3∣≥2, ∣A4∣≥3, ∣A5∣≥4.
Similarly for ∣Bi∣.
First suppose ∣A1∣=4. Since ∣A1∩B5∣=4, we have A1⊆B5, thus A1∩A5⊆B5∩A5=∅. It follows that ∣Bi∣≥∣(A1∪A5)∩Bi∣=∣A1∩Bi∣+∣A5∩Bi∣=4. Hence ∑∣Bi∣≥20. Similarly, if ∣A5∣=4, then ∑∣Bi∣≥20.
Now suppose ∣A3∣=2. Then ∣A3∩B1∣=∣A3∩B5∣=2 implies that A3⊆B1∩B5. Hence ∣B1∣≥∣A5∩B1∣+∣B5∩B1∣≥6. Analogously, we have ∣B5∣≥6, therefore ∑∣Bi∣≥6+3+2+3+6=20.
Finally, if ∣A1∣≥5, ∣A3∣≥3, ∣A5∣≥5, then we have ∑∣Ai∣≥5+3+3+3+5=19. Thus we have S≥19 and it suffices to find an example with ∑∣Ai∣=∑∣Bi∣=19:
A1A2A3A4A5={a2,a4,b1,b2,b5}={a4,a5,b1}={a1,a5,b1}={a1,a3,a5}={a1,a3,b3,b4,b5}{a1,a3,a5,b3,b4}{a1,a3,b5}{a3,a4,b5}{a4,b1,b5}{a2,a4,a5,b1,b2}=B1=B2=B3=B4=B5