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