#include <bits/stdc++.h>
using namespace std;
int a[3], b[3];
int dof[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool can() {
  if (b[1] > 12) return false;
  if (b[1] != 2 || b[2] % 4) {
    if (b[0] > dof[b[1] - 1]) return false;
  } else if (b[0] > 29)
    return false;
  if (a[2] - b[2] > 18)
    return true;
  else if (a[2] - b[2] == 18) {
    if (a[1] - b[1] > 0)
      return true;
    else if (a[1] - b[1] == 0) {
      if (a[0] >= b[0]) return true;
    }
  }
  if (a[2] % 4 && a[2] - b[2] == 18 && a[1] == 3 && a[0] == 1 && b[1] == 2 &&
      b[0] == 29) {
    return true;
  }
  return false;
}
int main() {
  scanf("%d.%d.%d", a, a + 1, a + 2);
  scanf("%d.%d.%d", b, b + 1, b + 2);
  sort(b, b + 3);
  bool ans = false;
  do {
    if (can()) ans = true;
  } while (next_permutation(b, b + 3));
  puts(ans ? "YES" : "NO");
  return 0;
}
