import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

let a = Int(split[0])!
let b = Int(split[1])!
let c = Int(split[2])!
let k = Int(split[3])!

var ans = 0


for i in 1...k {
    if i <= a {
        ans += 1
    } else if i <= a + b {
        continue
    } else if i <= a + b + c {
        ans -= 1
    }
}

print(ans)