#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
int n;
long long a[maxn], b[maxn], c[maxn], d[maxn], e[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  n += 2;
  for (int i = 2; i < n; i++) {
    cin >> a[i];
    --a[i];
  }
  e[0] = e[1] = 1;
  for (int i = 2; i < n; i++) {
    if (a[i - 1] <= a[i]) {
      b[i] = 1;
      c[i] = a[i - 1];
      d[i] = e[i - 1];
    } else if (a[i] < c[i - 1]) {
      b[i] = (1 + a[i] * d[i - 1]) % mod;
      c[i] = 0;
    } else {
      b[i] = (1 + (a[i] - c[i - 1]) * b[i - 1] + c[i - 1] * d[i - 1]) % mod;
      c[i] = 0;
    }
    e[i] = (1 + (a[i] - c[i]) * b[i] + c[i] * d[i]) % mod;
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    res = (res + e[i] - 1) % mod;
  }
  cout << res << '\n';
  return 0;
}
