freopen('dinner','r',stdin)
freopen('dinner','w',stdout)
input 'a'
input 'n'
input 'b'
input 'c'
input 'd'
input 'e'
import 'a'
import 'b'
import 'n'
import 'c'
import 'd'
import 'e'
def dinner()
    if(a+b+c+d+e>n):
    print(a+b+c)
    elif(a==None and b==None and c+d+e>n):
    print(c+d+e)
    else:
        print(n)
dinner()   
