#include <bits/stdc++.h>
using namespace std;
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  int a[3], b[3];
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  scanf("%d.%d.%d", &b[0], &b[1], &b[2]);
  sort(b, b + 3);
  bool ans = 0;
  do {
    bool valid = true;
    for (int i = (int)(0); i < (int)(3); ++i)
      if (b[i] <= 0) valid = false;
    if (!valid) continue;
    if (b[2] >= a[2] || b[1] > 12) continue;
    int days = day[b[1] - 1];
    if (b[1] == 2 && b[2] % 4 == 0) days++;
    if (b[0] > days) continue;
    if (a[2] - b[2] < 18) continue;
    if (a[2] - b[2] > 18) {
      ans = 1;
      break;
    }
    if ((a[1] > b[1]) || (a[1] == b[1] && a[0] >= b[0])) {
      ans = 1;
      break;
    }
  } while (next_permutation(b, b + 3));
  if (ans)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
