HIV/AIDS

How does someone get HIV?  I know that if you have sex with someone infected with HIV then you get it but how does it start in the first place?  If you can't get it without having sex/ sharing needles with someone that has it how did that first person get it? 
So like if my boyfriend and I don't have it and we have sex and if we did.. Anal.  Is there any way that we could form it together?