#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int *line;
  line = new int[N];
  long long answer = 0;
  for (int i = 0; i < N; ++i) {
    cin >> line[i];
    answer += line[i];
  }
  int nowmin;
  for (int i = 0; i < N - 1; ++i) {
    nowmin = line[i];
    for (int j = i + 1; j < N; ++j) {
      answer += nowmin = min(nowmin, line[j]);
    }
  }
  cout << answer << endl;
  return 0;
}
