#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
int dd, mm, yy;
const int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool valid(int y, int m, int d) {
  if (m > 12) return 0;
  if (y % 4 == 0 && m == 2) return d <= days[m - 1] + 1;
  return d <= days[m - 1];
}
bool ok(int y, int m, int d) {
  if (y < yy - 18) return 1;
  if (y > yy - 18) return 0;
  if (mm > m || (mm == m && dd >= d)) return 1;
  return 0;
}
int main() {
  scanf("%d.%d.%d", &dd, &mm, &yy);
  int b[3];
  scanf("%d.%d.%d", b, b + 1, b + 2);
  sort(b, b + 3);
  do {
    if (valid(b[0], b[1], b[2])) {
      if (ok(b[0], b[1], b[2])) {
        puts("YES");
        return 0;
      }
    }
  } while (next_permutation(b, b + 3));
  puts("NO");
}
