=LET(z,FILTERXML("<x><y>"&SUBSTITUTE(TEXTJOIN(",",,TRANSPOSE(A1:B5)),",","</y><y>")&"</y></x>","//y"),UNIQUE(FILTER(z,z<>0)))
=LET(
a,A1:A5,
b,B1:B5,
ra,ROWS(a),
rb,ROWS(b),
rsq,SEQUENCE(ra+rb),
csq,SEQUENCE(,COLUMNS(a)),
array,IFS(rsq<=ra,INDEX(a,rsq,csq),rsq<=ra+rb,INDEX(b,rsq-ra,csq)),
UNIQUE(FILTER(array,array<>0)))