T105951
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h,m,x,cnt,old;
main()
{
scanf("%lld:%lld",&h,&m);
cin>>x;
x=x%60*24;
ll t=h*60+m;
old=t;
while(true)
{
if(h%10==m/10&&h/10==m%10)
{
cout<<h<<':'<<m<<endl<<cnt;
break;
}
t-=x;
if(t==old)
{
cout<<"No Solution";
break;
}
if(t<24*60)
{
t+=24*60;
}
cnt++;
}
}