#include using namespace std; int main() { int N,H,M,T;cin>>N>>H>>M>>T; M+=T*(N-1); while(M>=60) { M-=60; H+=1; } while(H>=24) { H-=24; } cout<