#include <bits/stdc++.h>
using namespace std;
const int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long a[3], b[3];
inline void check(int d, int m, int y) {
  if (m > 12) {
    return;
  }
  if (months[m] < d - (y % 4 == 0 && m == 2)) {
    return;
  }
  if (a[2] - y > 18 || a[2] - y == 18 && a[1] > m ||
      a[2] - y == 18 && a[1] == m && a[0] >= d) {
    cout << "YES";
    exit(0);
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  scanf("%I64d.%I64d.%I64d", &a[0], &a[1], &a[2]);
  scanf("%I64d.%I64d.%I64d", &b[0], &b[1], &b[2]);
  sort(b, b + 3);
  check(b[2], b[1], b[0]);
  check(b[1], b[2], b[0]);
  check(b[2], b[0], b[1]);
  check(b[0], b[2], b[1]);
  check(b[1], b[0], b[2]);
  check(b[0], b[1], b[2]);
  cout << "NO";
}
