Get highest priority from subtasks and assign value to main issue

Hello everyone,
It’s my first post here :slight_smile:
I’m running on Jira Server 7.6.0. I’m struggling with problem like in title. I have to find a way to get highest value of priority from subtasks and rewrite it to main issue. Can someone suggest me how can I do this?

I guess i need to write listener which on subtask update will find priority and add value to main issue. What is the easiest way to achieve that?

Best regards,
Kamil