#include using namespace std; typedef long long ll; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int a,b; string s; cin>>a>>b>>s; int n=s.size(); if(n==5){ int t = (int)s[n-1] - '0'; a+=t-9; a+=24; a%=24; } if(n==6){ int t = (int)s[4] - '0'; t*=10; t += (int)s[5] - '0'; a+=t-9; a+=24; a%=24; } else if(n==7){ int t=(int)s[4]-'0'; a+=t-9+24; a%=24; t = (int) s[n-1]-'0'*6; b+=t; if(b>=60) a++; a%=24; b%=60; } else { int t = (int)s[4] - '0'; t*=10; t += (int)s[5] - '0'; a+=t-9+24; a%=24; t = (int) s[n-1]-'0'*6; b+=t; if(b>=60) a++; a%=24; b%=60; } if(a<10){ cout<<0<