You can do this with four semaphores. One means "A read an even location". One means "B wrote an even location". One means "A read an odd location". The last means "B wrote an odd location".
A reads a[0], then signals the first semaphore M times, then waits on the second semaphore M times. B writes b[0] then signals the second semaphore once.
Then A reads a[1], signals the third semaphore M times, and waits on the fourth semaphore M times. B writes b[1] and signals the fourth semaphore once.
Then you toggle between the semaphores as you handle the odd/even elements of the array.
Pretty clearly a homework question, since this does not seem like a realistic scenario.