#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 7;
int a, ta, b, tb;
int h, m;
int main() {
  cin >> a >> ta;
  cin >> b >> tb;
  scanf("%d: %d", &h, &m);
  int l = h * 60 + m;
  int r = 0;
  if ((l - 300) % a == 0)
    r = l + ta;
  else {
    r = a - l % a + l + ta;
    l = l + a - l % a;
  }
  int ed = r;
  r = min(r, 1439);
  l = max(300, l - tb + 1);
  long long ans = 0;
  for (int i = l; i <= r; i++) {
    if ((i - 300) % b == 0 && ed != i) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
