D

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;


int h1,m1,s1;
int h2,m2,s2;
ll ans = 0;
bool cmp(){
    if(h1 != h2) return h1 < h2;
    if(m1 != m2) return m1 < m2;
    else return s1 < s2;
}
int main(){
    // debug;
    ios;
    scanf("%d:%d:%d",&h1,&m1,&s1);
    scanf("%d:%d:%d",&h2,&m2,&s2);
    if(!cmp()){
        swap(h1,h2);
        swap(m1,m2);
        swap(s1,s2);
    }
    if(s2 < s1) ans += s2 + 60 - s1,m2-=1;
    else ans += s2-s1;
    if(m2 < m1) ans += (m2 + 60 - m1)*60,h2-=1;
    else ans += (m2 - m1)*60;
    ans += (h2-h1) * 3600;
    cout <<ans<<'\n';
    return 0;
}