/**
 *    author:  tourist
 *    created: 26.10.2022 18:30:24       
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int Read() {
  string s;
  cin >> s;
  int h = (int) (s[0] - '0') * 10 + (int) (s[1] - '0');
  int m = (int) (s[3] - '0') * 10 + (int) (s[4] - '0');
  return h * 60 + m;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t1 = Read();
  int t2 = Read();
  int d = t2 - t1;
  if (d < 0) d += 1440;
  int ans = d % 60 + d / 60;
  //ans = min(ans, (60 - d % 60) + (d / 60 + 1));
  cout << ans << '\n';
  return 0;
}
