# -*- coding: utf-8 -*- """ Created on Sun Sep 26 11:31:55 2021 @author: 大翔 """ a,b,c,d,m=map(int,input().split()) if b+d <= m: print(b+d) else: print(m-1)