Help understanding this inputs and outputs

When using the type of relay board that energizes the relay on a LOW input, you should always set the port pins HIGH before pinModing to OUTPUT so there is not a very short ON time before the pin is set to OUTPUT.
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);