Function to assigning Lead

Function to assigning Lead

Hello. I need your help. I need a function (with a button in Leads), that could select all leads on the first stage, take the oldest one and set current user (who clicked the button) as a responsible for this lead. I understand that it is possible to provide such function with custom functions, but I have never used Deluge and I need help.
I'm totally understand the algorithm. I have to update field "Owner" (to current user) in the first record of selection (leads with definite stage) sorted by Creation time.
Please, help to create this function!