The total number of edges in two regular polygons is $2014$, and the total number of diagonals is $1,014,053$. How many edges does the polygon with the smaller number of edges have?

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