#include using namespace std; int main(){ int n,h,m,t,x;cin>>n>>h>>m>>t; x=h*60+m+t*(n-1); cout<<(x/60)%24<