#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, k, l, a, b, gcd, lcm, tmp, s, c, x, y;
  cin >> n;
  long long arr[n + 10];
  x = y = -100000;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] > x) {
      x = arr[i];
    }
  }
  a = arr[0];
  b = arr[1];
  k = a;
  l = b;
  if (a < b) {
    k = a;
    a = b;
    b = k;
  }
  if (b == 0) {
    gcd = a;
  } else {
    while (a % b != 0) {
      tmp = b;
      b = a % b;
      a = tmp;
    }
    gcd = b;
  }
  lcm = (k * l) / gcd;
  for (i = 2; i < n; i++) {
    a = lcm;
    b = arr[i];
    k = a;
    l = b;
    if (a < b) {
      k = a;
      a = b;
      b = k;
    }
    if (b == 0) {
      gcd = a;
    } else {
      while (a % b != 0) {
        tmp = b;
        b = a % b;
        a = tmp;
      }
      gcd = b;
    }
    lcm = (k * l) / gcd;
  }
  k = lcm / x;
  k = (k - 1) * x;
  c = 0;
  for (i = (lcm - 1); i > k; i--) {
    s = 0;
    for (j = 0; j < n; j++) {
      s += (i % arr[j]);
    }
    if (s > c) {
      c = s;
    }
  }
  cout << c << endl;
  return 0;
}
