#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debug(T v, string delimiter = "\n") {
  for (__typeof(v.begin()) it = v.begin(), it_end = v.end(); it != it_end; it++)
    cout << *it << delimiter;
  cout << flush;
}
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
string ds = "SENW";
int days[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                   {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
bool solve(int DD, int MM, int YY, int BD, int BM, int BY) {
  if (BM < 1 || BM > 12) return false;
  bool leap = BY % 4 == 0;
  if (BD > days[leap][BM - 1]) return false;
  if (BY > YY - 18) return false;
  if (BY == YY - 18) {
    if (MM > BM) return true;
    if (MM < BM) return false;
    if (DD >= BD) return true;
    return false;
  } else {
    return true;
  }
}
int main(int argc, char** argv) {
  int DD, MM, YY;
  int BD, BM, BY;
  scanf("%2d.%2d.%2d", &DD, &MM, &YY);
  scanf("%2d.%2d.%2d", &BD, &BM, &BY);
  bool ok = solve(DD, MM, YY, BD, BM, BY) || solve(DD, MM, YY, BD, BY, BM) ||
            solve(DD, MM, YY, BM, BD, BY) || solve(DD, MM, YY, BY, BD, BM) ||
            solve(DD, MM, YY, BM, BY, BD) || solve(DD, MM, YY, BY, BM, BD);
  puts(ok ? "YES" : "NO");
  return 0;
}
