#include <bits/stdc++.h>
using namespace std;
struct Date {
  int days, months, years;
  Date(int d, int m, int y) {
    days = d;
    months = m;
    years = y;
  }
};
const int months_l[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int getdays(Date d) {
  int result = d.years * 365;
  for (int i = 1; i < d.months; ++i) {
    result += months_l[i - 1];
  }
  result += d.days;
  result += (d.years - 1) / 4;
  return result;
}
int diff_2(Date ev, Date born) {
  int result = ev.years - born.years;
  if (born.months == 2 && born.days == 29) {
    born.months = 3;
    born.days = 1;
  }
  if (ev.months < born.months ||
      (ev.months == born.months && ev.days < born.days))
    result--;
  return result;
}
int diff(Date ev, Date born) { return getdays(ev) - getdays(born); }
bool isvalid(Date d) {
  if (d.months > 12) return false;
  if (d.years % 4 == 0 && d.months == 2 && d.days == 29) return true;
  if (months_l[d.months - 1] < d.days) return false;
  return true;
}
void sol() {
  char temp;
  int dd, mm, yy, bd, bm, by;
  cin >> dd >> temp >> mm >> temp >> yy;
  cin >> bd >> temp >> bm >> temp >> by;
  Date ev(dd, mm, yy);
  Date born[] = {Date(bd, bm, by), Date(bd, by, bm), Date(bm, bd, by),
                 Date(bm, by, bd), Date(by, bm, bd), Date(by, bd, bm)};
  for (int i = 0; i < 6; i++)
    if (isvalid(born[i]) && diff_2(ev, born[i]) >= 18) {
      cout << "YES" << endl;
      return;
    }
  cout << "NO" << endl;
}
int main() {
  sol();
  return 0;
}
