1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#include <bits/stdc++.h>
using namespace std;

#define pll pair<long long, long long>
#define pii pair<int,int>
#define px first
#define py second
#define ll long long
#define eb emplace_back
#define vc vector

struct _debugger{
    void LGdebug(vector<vector<ll>> &g){
        cout << "GRAPH IS:\n";
        for(unsigned ll i=0; i<g.size(); i++){
            cout << i <<": ";
            for(auto c: g[i]) cout << c << " ";
            cout << "\n";
        }
        cout << "----------\n";
    }
    void LWGdebug(vector<vector<pll>> &g){
        cout << "WEIGHTED GRAPH IS:\n";
        for(unsigned ll i=0; i<g.size(); i++){
            cout << i <<": ";
            for(auto c: g[i]) cout << "{x: " << c.px << ", y: " << c.py << "} ";
            cout << "\n";
        }
        cout << "----------\n";
    }
    void LVdebug(vector<ll> &v ){
        cout << "VECTOR IS: " << "\n";
        for(unsigned ll i=0; i<v.size(); i++) cout << i << ": " << v[i] << "\n";
        cout << "---------\n";
    }
    void Gdebug(vector<vector<int>> &g){
        cout << "GRAPH IS:\n";
        for(unsigned ll i=0; i<g.size(); i++){
            cout << i <<": ";
            for(auto c: g[i]) cout << c << " ";
            cout << "\n";
        }
        cout << "----------\n";
    }
    void WGdebug(vector<vector<pii>> &g){
        cout << "WEIGHTED GRAPH IS:\n";
        for(unsigned ll i=0; i<g.size(); i++){
            cout << i <<": ";
            for(auto c: g[i]) cout << "{x: " << c.px << ", y: " << c.py << "} ";
            cout << "\n";
        }
        cout << "----------\n";
    }
    void Vdebug(vector<int> &v ){
        cout << "VECTOR IS: " << "\n";
        for(unsigned ll i=0; i<v.size(); i++) cout << i << ": " << v[i] << "\n";
        cout << "---------\n";
    }
    void VPdebug(vector<pii> &v ){
        cout << "VECTOR IS: " << "\n";
        for(unsigned ll i=0; i<v.size(); i++) cout << i <<": " << "{x: " << v[i].px << ", y: " << v[i].py << "} \n";
        cout << "---------\n";
    }
};

_debugger deBug;
const ll linf = 4e18;   
const int inf = 1e9;
const int NN = 1e5+67;

ll minutify(ll d, ll h, ll m){
    return m + h*60 + d*24*60;
}

void solve(){
  
    ll round, d, h, m;
    cin >> round >> d >> h >> m;
    ll D,H,M;

    if(round==1){
        D = 24; H = 23; M = 59;
    }
    else if(round == 2){
        D = 25; H = 23; M = 59;
    }
    else if(round == 3){
        D = 26; H = 23; M = 59;
    }
    else if(round == 4){
        D = 27; H = 23; M = 59;
    }
    else if(round == 5){
        D = 29; H = 22; M = 59;
    }

    cout << minutify(D,H,M) - minutify(d,h,m) + 1;
}




signed main(){
    cin.tie(0) -> sync_with_stdio(0);
    //int t; cin >> t; 
    //while(t--)
        solve();
    return 0;
}