# -*- coding: utf-8 -*-
"""
Created on Fri Jan 26 16:39:39 2018

@author: Abstergo
"""

a=input()
b=input()
c=input()
d=input()
e=input()
cnt=0
if a>c:
    print(a);
    
    '''
else:
  rema = a-c*2;
if (e*3-b)>0:
  cnt+=(e*3-b);
else:
  remb = e*3-b;
if rema<d:
  cnt+=d-rema;
if remb<d:
  cnt+=d-remb;
print(cnt)
