#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int a[3], b[3];
bool valid() {
  int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  if (b[2] % 4 == 0) m[1]++;
  return (1 <= b[1] && b[1] <= 12 && 1 <= b[0] && b[0] <= m[b[1] - 1]);
}
int main() {
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  scanf("%d.%d.%d", &b[0], &b[1], &b[2]);
  sort(b, b + 3);
  do {
    if (valid()) {
      if (b[2] < a[2] - 18 ||
          b[2] == a[2] - 18 && (b[1] < a[1] || b[1] == a[1] && b[0] <= a[0])) {
        printf("YES\n");
        return 0;
      }
    }
  } while (next_permutation(b, b + 3));
  printf("NO\n");
  return 0;
}
