#include<bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
int a[N];
priority_queue<int, vector<int>, greater<int>>p;//升序
priority_queue<int>q;//降序
int main()
{
int n, x;
cin >> n;
int cnt = 0;
while (cin >> x && x)
{
a[cnt ++ ] = x;
p.push(x);
q.push(x);
}
int s1, s2;
while (p.size() != 1)
{
int t = p.top();
p.pop();
int t2 = p.top();
p.pop();
p.push(t2 * t + 1);
}
while (q.size() != 1)
{
int t = q.top();
q.pop();
int t1 = q.top();
q.pop();
q.push(t * t1 + 1);
}
int ans = p.top() - q.top();
cout << ans << endl;
}