#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 123;
const long long INF = (long long)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
int mult(int a, int b) { return (1ll * a * b) % MOD; }
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int n, a[N], res, s[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  a[0] = inf;
  for (int r = 2; r <= n; r++) {
    s[r] = add(mult(s[r - 1], min(a[r - 2], min(a[r - 1], a[r])) - 1),
               min(a[r - 1], a[r]) - 1);
  }
  for (int i = 1; i <= n; i++) {
    res = add(res, a[i] - 1);
    if (i > 1) {
      res = add(res, mult(s[i], min(a[i - 1], a[i]) - 1));
    }
  }
  printf("%d", res);
  return 0;
}
