var readline  = require('readline').createInterface(process.stdin, process.stdout);
var result = 0;
var temp = 0;
readline.on('line', function(line) {
  if ( temp > 0) {
    result += Math.min(temp, parseInt(line));
    temp = 0
  } else {
    temp = parseInt(line);
  }
});

readline.on('close', function(line) {
  console.log(result);
});
