I have data in the following format.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(x1 x2 x3 x4 x5 )
1 . 3 4 2
2 . . . . 
. 2 . 3 1  
. . . . . 
. . . 4 3 
. 5 2 . .
. . 1 . 5
. 2 . 3 .
end
How can I easily generate a new variable, say x6 that is equal to x1, but replacing missing values of x1 with non missing values of x4 and if x4 is missing, replace by x3, if x3 is missing replace by x2, if x2 is missing replace by x5. If all x1 x2 x3 x4 x5 are missing, x6 remains missing.
Thanks