You are given an array a_1,a_2,…,a_n. Let x_1=a_1, and x_i=x_i−1moda_i for each i from 2 to n.
Suppose that we can rearrange a_1,…,a_n in any way. What is the largest possible value of x_n we can obtain?
The first line contains an integer n --- the size of the array (2≤n≤105).
The second line containing n integers a_1,…,a_n (1≤a_i≤105).
Print one integer --- the largest possible value of x_n.