Module Program
Sub Main(args As String())
        Dim sInput As String() = Split(Console.ReadLine(), " ")

        Dim iInputA As Integer = sInput(0)
        Dim iInputB As Integer = sInput(1)
        Dim iInputC As Integer = sInput(2)
        Dim iInputK As Integer = sInput(3)

        If iInputA + iInputB >= iInputK Then
            Console.WriteLine(iInputA * 1)
        ElseIf iInputA + iInputB <= iInputK Then
            'ElseIf iInputA + iInputB + iInputC >= iInputK Then
            Console.WriteLine((iInputA * 1) + ((iInputK - iInputA - iInputB) * -1))
        End If

    End Sub
End Module