#include <bits/stdc++.h> using namespace std; int main(){int h,m,s;char a;cin>>h>>m>>s>>a;if(a=='P')h+=12;cout<<h3600+m60+s<<"\n";}