#include <bits/stdc++.h>
using namespace std;
const int ms[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int d, m, y, a, b, c;
int check(int a, int b, int c) {
  if (b < 1 || b > 12 || a < 1 || a > ms[b] + int(b == 2 && c % 4 == 0))
    return 0;
  return (c + 18 < y || c + 18 == y && b < m ||
          c + 18 == y && b == m && a <= d);
}
int main() {
  scanf("%d.%d.%d", &d, &m, &y);
  scanf("%d.%d.%d", &a, &b, &c);
  if (check(a, b, c) || check(a, c, b) || check(b, a, c) || check(b, c, a) ||
      check(c, a, b) || check(c, b, a))
    cout << "YES";
  else
    cout << "NO";
}
