const lineList = require('fs').readFileSync('/dev/stdin','utf8').trim().split('\n')

const n = parseInt(lineList[0])
const b = lineList[1].split(' ').map(e => parseInt(e))
var a = 0

a += b[0]
for(var i=0;i<b.length;i++) {
  a += b[i]

  if(b[i-1] > b[i]) {
    a -= b[i-1]
    a += b[i]
  }
}

console.log(a)
