#include <bits/stdc++.h>
using namespace std;
int mon[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                  {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int dd, mm, yy;
int judge(int d, int m, int y) {
  if (m < 1 || m > 12) return 0;
  if (d < 1 || d > mon[y % 4 == 0][m]) return 0;
  if (y + 18 != yy) return y + 18 < yy ? 1 : 0;
  if (m != mm) return m < mm ? 1 : 0;
  return d <= dd ? 1 : 0;
}
int main() {
  int s[3];
  bool f;
  while (scanf("%d.%d.%d", &dd, &mm, &yy) != EOF) {
    f = true;
    scanf("%d.%d.%d", &s[0], &s[1], &s[2]);
    do {
      if (judge(s[0], s[1], s[2])) {
        cout << "YES" << endl;
        f = false;
        break;
      }
    } while (next_permutation(s, s + 3));
    if (f) cout << "NO" << endl;
  }
  return 0;
}
