#include <bits/stdc++.h>
using namespace std;
int mon[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int valid(int d, int m, int y) {
  if (y % 4 == 0)
    mon[1] = 29;
  else
    mon[1] = 28;
  if (m >= 1 && m <= 12) {
    if (d <= mon[m - 1]) return 1;
    return 0;
  } else {
    return 0;
  }
}
int good(int bd, int bm, int by, int d, int m, int y) {
  if (y - by > 18) return 1;
  if (y - by < 18) return 0;
  if (bm < m) return 1;
  if (bm > m) return 0;
  if (bd <= d) return 1;
  return 0;
}
int main() {
  int p[3];
  int d, m, y;
  scanf("%d.%d.%d", &d, &m, &y);
  scanf("%d.%d.%d", &p[0], &p[1], &p[2]);
  do {
    if (valid(p[0], p[1], p[2])) {
      if (good(p[0], p[1], p[2], d, m, y)) {
        printf("YES\n");
        return 0;
      }
    }
  } while (next_permutation(p, p + 3));
  printf("NO\n");
  return 0;
}
