#include <bits/stdc++.h>
using namespace std;
const int din[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool ct(int d, int m, int y) {
  if (d > 31 || m > 12 || y > 99) return false;
  int dc = din[m - 1];
  if (y % 4 == 0 && m == 2) dc++;
  if (d > dc) return false;
  return true;
}
bool gd(int db, int mb, int yb, int df, int mf, int yf) {
  yb += 18;
  if (yb > yf) return false;
  if (yb < yf) return true;
  if (mb > mf) return false;
  if (mb < mf) return true;
  if (db > df) return false;
  return true;
}
int main() {
  int db, mb, yb, df, mf, yf;
  scanf("%d.%d.%d", &df, &mf, &yf);
  scanf("%d.%d.%d", &db, &mb, &yb);
  if (ct(db, mb, yb) && gd(db, mb, yb, df, mf, yf)) {
    printf("YES\n");
    return 0;
  }
  if (ct(db, yb, mb) && gd(db, yb, mb, df, mf, yf)) {
    printf("YES\n");
    return 0;
  }
  if (ct(mb, db, yb) && gd(mb, db, yb, df, mf, yf)) {
    printf("YES\n");
    return 0;
  }
  if (ct(mb, yb, db) && gd(mb, yb, db, df, mf, yf)) {
    printf("YES\n");
    return 0;
  }
  if (ct(yb, db, mb) && gd(yb, db, mb, df, mf, yf)) {
    printf("YES\n");
    return 0;
  }
  if (ct(yb, mb, db) && gd(yb, mb, db, df, mf, yf)) {
    printf("YES\n");
    return 0;
  }
  printf("NO\n");
  return 0;
}
