solution of GetMainElement