#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - 48; isdigit(ch = getchar());
       res = (res << 1) + (res << 3) + ch - 48)
    ;
  flag && (res = -res);
}
template <typename T>
void Out(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) Out(x / 10);
  putchar(x % 10 + '0');
}
int t[3];
int d[100] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
int check(int my0, int my1, int my2) {
  if (t[2] - 18 > my2) {
    return cout << "YES" << '\n', 0;
  }
  if (t[2] - 18 == my2) {
    if (t[1] > my1) {
      return cout << "YES" << '\n', 0;
    } else if (t[1] == my1) {
      if (t[0] >= my0) {
        return cout << "YES" << '\n', 0;
      }
    }
  }
  return -1;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int my[3];
  char temp;
  cin >> t[0] >> temp >> t[1] >> temp >> t[2];
  cin >> my[0] >> temp >> my[1] >> temp >> my[2];
  int res = check(my[0], my[1], my[2]);
  if (res == 0) return 0;
  if (my[2] <= 12 &&
      my[0] <= (d[my[2]] == 28 ? (my[1] % 4 == 0 ? 29 : 28) : d[my[02]])) {
    res = check(my[0], my[2], my[1]);
  }
  if (res == 0) return 0;
  if (my[2] <= 12 &&
      my[1] <= (d[my[2]] == 28 ? (my[0] % 4 == 0 ? 29 : 28) : d[my[2]])) {
    res = check(my[1], my[2], my[0]);
  }
  if (res == 0) return 0;
  if (my[0] <= 12 &&
      my[1] <= (d[my[0]] == 28 ? (my[2] % 4 == 0 ? 29 : 28) : d[my[0]])) {
    res = check(my[1], my[0], my[2]);
  }
  if (res == 0) return 0;
  if (my[1] <= 12 &&
      my[2] <= (d[my[1]] == 28 ? (my[0] % 4 == 0 ? 29 : 28) : d[my[1]])) {
    res = check(my[2], my[1], my[0]);
  }
  if (res == 0) return 0;
  if (my[0] <= 12 &&
      my[2] <= (d[my[0]] == 28 ? (my[1] % 4 == 0 ? 29 : 28) : d[my[0]])) {
    res = check(my[2], my[0], my[1]);
  }
  if (res == 0) return 0;
  return cout << "No" << '\n', 0;
  return 0;
}
