#include <bits/stdc++.h>
using namespace std;
int DD, MM, YY;
int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int normal[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool f(int bd, int bm, int by) {
  if (bm > 12 || bm == 0) return 0;
  if (by % 4 == 0) {
    if (bd == 0 || bd > leap[bm - 1]) return 0;
  } else {
    if (bd == 0 || bd > normal[bm - 1]) return 0;
  }
  if (by + 18 > YY) return 0;
  if (by + 18 < YY) return 1;
  if (MM < bm) return 0;
  if (MM > bm) return 1;
  if (DD < bd) return 0;
  return 1;
}
int main() {
  int bd, bm, by;
  char s;
  cin >> DD >> s >> MM >> s >> YY;
  cin >> bd >> s >> bm >> s >> by;
  if (f(bd, bm, by) || f(bd, by, bm) || f(by, bd, bm) || f(by, bm, bd) ||
      f(bm, by, bd) || f(bm, bd, by))
    cout << "YES";
  else
    cout << "NO";
}
