#include<iostream> using namespace std; int main() { int s,f,m,sum=0; cher ch; cin>>s>>f>>m>>ch; if(ch=='p') s+=12; cout<<s*60*60+f*60+m; return 0; }