Let us say that you want a1 and a2 to be in adjacent slots.
Can you calculate the number C of all possibilities how to divide 7 objects a3,...,a9 into the 5 slots?
Now, if a3,...,a9 are divided, you have to put a1 and a2 into two adjacent slots. So the actual result is
where N denotes the number of possibilities how to put a1 and a2 into adjacent slots.
I'd like to show you that N=8.
One way to see this: If you place a1 into the first or into the 5th slot, you have only one possibility where to put a2. (This gives you possibilities.)
If you put a1 into one of the remaining slots, you have always two possibilities for a2. (This gives you 3*2=6 possibilities).
So there are altogether 8 of them.
If a1 and a2 are supposed to be adjacent, then they are placed in one of these two orders:
a1,a2 or a2,a1
Of course you have only four possibilities where to put the left one.
So you have 2*4=8 possibilities.