#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    scanf("%d",&n);
    long int a[n],i,ans=0,max=0,j,max1=0,sum=0;
    long int ans1;
    for(i=0;i<n;++i)
        { scanf("%ld",&a[i]);
           if(max<a[i])
              max=a[i];
        }
        
    ans=a[0];
    for(i=1;i<n;++i)
       {
           ans=(ans*a[i])/(__gcd(ans,a[i]));
       }
       
  
    for(i=ans-1;i>=max;--i)
       {
           sum=0;
           for(j=0;j<n;++j)
              {
                  sum+=i%a[j];
              }
              
             if(max1<sum)
                 max1=sum;
            
       }
       
    printf("%ld",max1);   
   
}