scoreboard players set min times_appeared 0

execute if score #holy_sword shop matches 1 if score min times_appeared matches -1 run scoreboard players operation min times_appeared = holy_sword times_appeared
execute if score #holy_sword shop matches 1 if score holy_sword times_appeared < min times_appeared run scoreboard players operation min times_appeared = holy_sword times_appeared

execute if score #ice_sword shop matches 1 if score min times_appeared matches -1 run scoreboard players operation min times_appeared = ice_sword times_appeared
execute if score #ice_sword shop matches 1 if score ice_sword times_appeared < min times_appeared run scoreboard players operation min times_appeared = ice_sword times_appeared

execute if score #katana shop matches 1 if score min times_appeared matches -1 run scoreboard players operation min times_appeared = katana times_appeared
execute if score #katana shop matches 1 if score katana times_appeared < min times_appeared run scoreboard players operation min times_appeared = katana times_appeared

execute if score #emerald_sword shop matches 1 if score min times_appeared matches -1 run scoreboard players operation min times_appeared = emerald_sword times_appeared
execute if score #emerald_sword shop matches 1 if score emerald_sword times_appeared < min times_appeared run scoreboard players operation min times_appeared = emerald_sword times_appeared

execute if score #crystal_sword shop matches 1 if score min times_appeared matches -1 run scoreboard players operation min times_appeared = crystal_sword times_appeared
execute if score #crystal_sword shop matches 1 if score crystal_sword times_appeared < min times_appeared run scoreboard players operation min times_appeared = crystal_sword times_appeared

execute if score #dark_mace shop matches 1 if score min times_appeared matches -1 run scoreboard players operation min times_appeared = dark_mace times_appeared
execute if score #dark_mace shop matches 1 if score dark_mace times_appeared < min times_appeared run scoreboard players operation min times_appeared = dark_mace times_appeared
execute if score min times_appeared matches -1 run scoreboard players set min times_appeared 0