#include int main(void){ long n; int h,m,t; std::cin >> n >> h >> m >> t; long c = 60*h + m + (n-1)*t; c=c%1440; h=c/60; m=c%60; std::cout << h <