#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int mon1[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[3];
int b[3];
int main() {
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  scanf("%d.%d.%d", &b[0], &b[1], &b[2]);
  do {
    if (b[1] > 12) continue;
    if (b[2] % 4 != 0 && b[0] > mon[b[1]]) continue;
    if (b[2] % 4 == 0 && b[0] > mon1[b[1]]) continue;
    if (b[2] + 18 < a[2]) {
      printf("YES\n");
      return 0;
    } else if (b[2] + 18 == a[2]) {
      if (b[1] < a[1]) {
        printf("YES\n");
        return 0;
      } else if (b[1] == a[1]) {
        if (b[0] <= a[0]) {
          printf("YES\n");
          return 0;
        }
      }
    }
  } while (next_permutation(b, b + 3));
  printf("NO\n");
  return 0;
}
