#include <bits/stdc++.h>
using namespace std;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isleap(int m, int y) {
  if (m != 2) return 0;
  return y % 4 == 0;
}
bool correct(int d, int m, int y) {
  if (m <= 0 || m > 12) return 0;
  if (y <= 0) return 0;
  if (d <= 0 || d > (days[m] + isleap(m, y))) return 0;
  return 1;
}
int dd, mm, yy;
bool check(int d, int m, int y) {
  if (yy - y < 18) return 0;
  if (yy - y > 18) return 1;
  if (mm > m) return 1;
  if (mm < m) return 0;
  if (dd == 28 && m == 2 && d == 29) return 1;
  if (dd >= d) return 1;
  return 0;
}
int main() {
  int a[3];
  scanf("%d.%d.%d", &dd, &mm, &yy);
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  bool ok = 0;
  sort(a, a + 3);
  do {
    if (!correct(a[0], a[1], a[2])) continue;
    ok |= check(a[0], a[1], a[2]);
  } while (next_permutation(a, a + 3));
  printf("%s\n", (ok ? "YES" : "NO"));
  return 0;
}
