#include <bits/stdc++.h>
using namespace std;
const int nd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dd, mm, yy, bd, bm, by;
inline bool check(int d, int m, int y) {
  if (m < 1 || m > 12 || d < 1 || d > nd[m] + int(m == 2 && y % 4 == 0))
    return 0;
  if (y + 18 < yy || y + 18 == yy && m < mm ||
      y + 18 == yy && m == mm && d <= dd)
    return 1;
  return 0;
}
int main() {
  scanf("%d.%d.%d", &dd, &mm, &yy);
  scanf("%d.%d.%d", &bd, &bm, &by);
  if (check(bd, bm, by) || check(bd, by, bm) || check(bm, bd, by) ||
      check(bm, by, bd) || check(by, bm, bd) || check(by, bd, bm))
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
