function [FirstSetsMetrics,FirstSets,IDs]=get1lev(PotSetsHierarchy,PotSetsMetric,PotSets,PotNodesMetric,PotNodes);
% Get the first level of the rules tree

dimension=size(PotNodes,1);
IDs=[1:1:size(PotNodes,2)];
j=0;
while (size(PotSetsHierarchy,1)>0),
	j=rem(j,size(PotSetsHierarchy,1))+1;
	Mask1=(IDs==PotSetsHierarchy(j,2));
	Mask2=(IDs==PotSetsHierarchy(j,3));
	if sum(Mask1)+sum(Mask2)==2,
		[NoUse,p1]=max(Mask1);
		[NoUse,p2]=max(Mask2);
		IDs(p1)=PotSetsHierarchy(j,1);
		IDs=[IDs(1:p2-1) IDs(p2+1:size(IDs,2))];
		PotSetsHierarchy=[PotSetsHierarchy(1:j-1,:);PotSetsHierarchy(j+1:size(PotSetsHierarchy,1),:)];
	end
end

for i=1:size(IDs,2),
	if IDs(i)<0,
		FirstSets(:,i)=PotSets(:,-IDs(i));
		FirstSetsMetrics(:,:,i)=PotSetsMetric(:,:,-IDs(i));
	else
		FirstSets(:,i)=PotNodes(:,IDs(i));
		FirstSetsMetrics(:,:,i)=PotNodesMetric(:,:,IDs(i));
	end
end
