#include using namespace std; int main(){ int n,h,m,t; cin>>n>>h>>m>>t; for(int i=1;i<=n-1;i++){ if(m+t>=60){ h++; m=(m+t)%60; } m+=t; } cout<