Define the sequences $a_n$ and $b_n$ as follows: $a_1 = 2017$ and $b_1 = 1$. 
For $n > 1$, if there is a greatest integer $k > 1$ such that $a_n$ is a perfect $k$th power, then $a_{n+1} =\sqrt[k]{a_n}$, otherwise  $a_{n+1} = a_n + b_n$. If $a_{n+1} \ge a_n$ then $b_{n+1} = b_n$, otherwise $b_{n+1} = b_n + 1$. Find $a_{2017}$.

Let's think step by step and output the final answer within \boxed{}.
user