#include <bits/stdc++.h>
using namespace std;
int D, M, Y;
bool f(int d, int m, int y) {
  if ((!m || m > 12)) return false;
  if (d > 31) return false;
  if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31) return false;
  if (m == 2 && (d > 29 || (y % 4 && d == 29))) return false;
  int vy = Y - y - 1;
  if (M > m || (M == m && D >= d)) vy++;
  return (vy >= 18);
}
int main() {
  int d, m, y;
  char S[10];
  cin >> S;
  D = (10 * (S[0] - '0') + S[1] - '0'), M = (10 * (S[3] - '0') + S[4] - '0'),
  Y = (10 * (S[6] - '0') + S[7] - '0');
  cin >> S;
  d = (10 * (S[0] - '0') + S[1] - '0'), m = (10 * (S[3] - '0') + S[4] - '0'),
  y = (10 * (S[6] - '0') + S[7] - '0');
  if (f(d, m, y) || f(d, y, m) || f(m, d, y) || f(m, y, d) || f(y, d, m) ||
      f(y, m, d))
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
  return 0;
}
