#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int l = 0;
long long int ans = 0;
int in[1000100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", in + i);
  }
  if (n == 1) {
    printf("%d", in[1] - 1);
    return 0;
  } else {
    l = min(in[1], in[2]) - 1;
    ans += in[1] - 1;
    for (int i = 2; i <= n; i++) {
      ans += (l * (min(in[i], in[i - 1]) - 1)) % mod + in[i] - 1;
      ans %= mod;
      l = (l * (min(min(in[i], in[i - 1]), in[i + 1]) - 1)) % mod +
          min(in[i], in[i + 1]) - 1;
      l %= mod;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
