fun main(args : Array<String>) {
    val (h1, m1, h2, m2, k) = readLine()!!.split(" ").map { it.toInt() }

    var h = h2-h1
    var m = m2-m1
    if (m < 0) {
        h -= 1
        m += 60
    }

    println(60*h + m - k)
}