"use strict";

function main(arg) {
    arg         = arg.split("\n");
    const train = arg.slice(0, 2);
    const bus   = arg.slice(-2);
    
    console.log(parseInt(Math.min(...train)) + parseInt(Math.min(...bus)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));