function main(input) {
  input = input.trim();
  const a = input.split('').map(Number);
  const b = input.split('').map(Number);
  const c = input.split('').map(Number);
  const d = input.split('').map(Number);

  console.log(Math.min(a,b)+Math.min(c,d));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));