#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int mod = (int)1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
int n, m, k;
long long dp[1000010];
int a[1000010];
int main() {
  long long sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  dp[0] = 1;
  a[0] = a[1];
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      sum = (sum + a[i] - 1) % mod;
    else
      sum =
          (sum + a[i] - 1 + dp[i - 1] * 1ll * (min(a[i], a[i - 1]) - 1) % mod) %
          mod;
    dp[i] = dp[i - 1] * 1ll * (min(a[i], min(a[i - 1], a[i + 1])) - 1) % mod;
    if (i > 1 && i < n) dp[i] = (dp[i] + min(a[i], a[i + 1]) - 1) % mod;
  }
  cout << sum << endl;
  return 0;
}
