#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int f[N], h[N];
int main() {
  auto _add = [&](int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
  };
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]--;
  int ans = 0;
  f[0] = 1;
  h[0] = 1e9 + 1;
  h[n + 1] = 1e9 + 1;
  for (int i = 1; i <= n; i++) {
    if (i > 1) _add(ans, f[i - 1] * 1ll * min(h[i], h[i - 1]) % mod);
    if (i > 1)
      _add(f[i], f[i - 1] * 1ll * min(min(h[i], h[i - 1]), h[i + 1]) % mod);
    _add(f[i], min(h[i], h[i + 1]));
    _add(ans, h[i]);
  }
  cout << ans;
}
