My task is to make `myReplace(E1,L1,E2,L2)` such that the very first occurrence of `E1` in `L1` gets replaced by `E2` and is returned in `L2`. I have written the below described code and it is working properly.

```
myReplace(E1,[],E2,[]).
myReplace(E1,[E1|Xs],E2,[E2|Ys]):-
  myReplace(E1,Xs,E1,Ys).
myReplace(E1,[H|Hs],E2,[H|Ts]):-
  E1 \= H,
  myReplace(E1,Hs,E2,Ts).

```

However, For example `myReplace(2,[1,2,3,2,1],5,X)` should give `X = [1,5,3,2,1]` and `X = [1,2,3,5,1]`. But my code is only giving one solution which is `X = [1,5,3,2,1]`.

Similarly, when `myReplace(2,X,5,[1,5,3,5,1])` should backtrack over the solutions `X = [1,2,3,5,1]` and `X = [1,5,3,2,1]` only, but my solution gives me one more solution as `X = [1,5,3,5,1]`.

Could you please help me resolve this.

Thank you :)