#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const int mod = 1e9 + 7;
int CASE = 1;
const int mxn = 2e5 + 1;
const long long infll = 1e18;
const int infi = 1e9;
bool prime(long long n) {
  if (n <= 1) return false;
  if (n == 2 or n == 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long __gcd(long long a, long long b) { return !b ? a : __gcd(b, a % b); }
long long power(long long a, long long b, long long MOD) {
  long long x = a, res = 1, p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
    x %= MOD, res %= MOD;
  }
  return res;
}
void solve() {
  int a, ta, b, tb;
  cin >> a >> ta >> b >> tb;
  string s;
  cin >> s;
  int time = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3, 2));
  int x = 300;
  vector<int> q;
  int ans = 0;
  for (long long i = x; i <= min(time + ta - 1, 23 * 60 + 59); i++) {
    for (long long j = 0; j < q.size(); j++) {
      q[j]++;
      if (q[j] == tb) q.erase(q.begin(), q.begin() + 1), j--;
    }
    if (i == time) ans = q.size();
    if ((i - x) % b == 0) {
      q.push_back(0);
      if (i >= time) ans++;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
