#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int d, m, y;
int a[3];
bool goodd(int d, int m, int y) {
  if (m > 13) return false;
  if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
    return (d <= 31);
  } else {
    if (m == 2) {
      if ((y % 4) == 0)
        return d <= 29;
      else
        return d <= 28;
    } else {
      return d <= 30;
    }
  }
}
bool good() {
  if (a[2] > y || a[2] == y && a[1] > m || a[2] == y && a[1] == m && a[0] >= d)
    return false;
  int d1 = a[0], m1 = a[1], y1 = a[2];
  if (!goodd(d1, m1, y1)) return false;
  if (y - y1 > 18 || y - y1 == 18 && m > m1 ||
      y - y1 == 18 && m == m1 && d >= d1)
    return true;
  return false;
}
int main() {
  scanf("%d.%d.%d", &d, &m, &y);
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  sort(a, a + 3);
  do {
    if (good()) {
      printf("YES\n");
      return 0;
    }
  } while (next_permutation(a, a + 3));
  printf("NO\n");
  return 0;
}
