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