Min value (transformed) of a group of related nodes

Hi all,
I need to get the node with the minimum value. Previously, I change the value of property 'M' to '8.5' and save it in the variable 'nivel'
Later I compare the values of 'nivel' staying with the nodes 'ra' with the lower level.
I do not know how I can get this minimum I have tried several ways and I can not get it to work.
Thanks.

MATCH (cen:CENTRO{name:'C0010810'})<-[r5:APLICA_DIRECTO_INCLUYE]-(rapc:RAPC)
MATCH (rapc)<-[r4:APLICA_CENTROS]-(cab:CabeceraAP)
//WHERE (COALESCE(rapc.fIniEfe,"") + COALESCE(rapc.cHoraIni,"")) <= '201909050000' <= (COALESCE(rapc.fFinEfe,"") + COALESCE(rapc.cHoraFin,""))
MATCH (cab)-[r3:APLICA_MERCANCIA_C|APLICA_MERCANCIA_D]->(rapm:RAPM)
MATCH (rapm)-[r2]->(n)
MATCH p = (b:BARRA{id:'B001015215407584'})-[r6:PERTENECE_A*..3]->(n) WITH *, relationships(p) AS rel
//OPTIONAL MATCH (b)<-[:PERTENECE_A]-(t:TALLA)
MATCH (cab)-[:APLICA_MERCANCIA_C|APLICA_MERCANCIA_D]->(ra:RAPM)-[re]->(n)
WHERE n:FAMILIA OR n:UNECO OR n:EMPRESA

// si la cab tiene varios ra
WITH cab, count(ra) as con, collect(ra) as ras 
UNWIND ras as ra
CALL apoc.when(
   con > 1,
  //codigo para cuando una cabecera tiene mas de un rapm, sacar el min del grupo
  'WITH ra.cNivelIn as nivel, ra, cab
		//cambiar la M por 8,5
		CALL apoc.when(
          nivel = "M",
          "RETURN 8.5 as nivel,cab,ra",
          "RETURN nivel as nivel,cab,ra",
        {nivel:nivel,cab:cab,ra:ra}) YIELD value as val1
	WITH val1.cab as cab1, val1.ra as ra1, val1.nivel as nivel
    //WITH apoc.agg.minItems(ra1,nivel) as mini, cab1
   RETURN cab1,ra1,nivel
   ',
  //(else) una cabecera tiene un solo rapm
  '',
  {ra:ra,cab:cab}) YIELD value as val2
 
 RETURN val2

the output:


in the green circle I have to keep the RA node that has value 2 (since it is the minimum between 2 and M 8.5)

I can't figure out how to group by ra and get the lowest level. I don't know how I have to group the nodes + the level
Thank you very much in advance

You might take a look at the following post.

Cypher query for return node which <some_field> = max(<some_field>) value out of a group of nodes - Neo4j Graph Platform - Neo4j Online Community