#include <bits/stdc++.h>
using namespace std;
bool good(int x, int y, int z) {
  if (y == 12 && x < 32) return true;
  if (y == 11 && x < 31) return true;
  if (y == 10 && x < 32) return true;
  if (y == 9 && x < 31) return true;
  if (y == 8 && x < 32) return true;
  if (y == 7 && x < 32) return true;
  if (y == 6 && x < 31) return true;
  if (y == 5 && x < 32) return true;
  if (y == 4 && x < 31) return true;
  if (y == 3 && x < 32) return true;
  if (y == 1 && x < 32) return true;
  if (y == 2 && x < 29) return true;
  if (y == 2 && x == 29 && z % 4 == 0) return true;
  return false;
}
int main() {
  int day, month, year;
  scanf("%d.%d.%d", &day, &month, &year);
  int a, b, c;
  scanf("%d.%d.%d", &a, &b, &c);
  if (good(a, b, c)) {
    if (year - c > 18) {
      printf("YES\n");
      return 0;
    }
    if (year - c == 18) {
      if (b < month) {
        printf("YES\n");
        return 0;
      }
      if (b == month && a <= day) {
        printf("YES\n");
        return 0;
      }
    }
  }
  if (good(b, a, c)) {
    if (year - c > 18) {
      printf("YES\n");
      return 0;
    }
    if (year - c == 18) {
      if (a < month) {
        printf("YES\n");
        return 0;
      }
      if (a == month && b <= day) {
        printf("YES\n");
        return 0;
      }
    }
  }
  if (good(a, c, b)) {
    if (year - b > 18) {
      printf("YES\n");
      return 0;
    }
    if (year - b == 18) {
      if (c < month) {
        printf("YES\n");
        return 0;
      }
      if (c == month && a <= day) {
        printf("YES\n");
        return 0;
      }
    }
  }
  if (good(c, a, b)) {
    if (year - b > 18) {
      printf("YES\n");
      return 0;
    }
    if (year - b == 18) {
      if (a < month) {
        printf("YES\n");
        return 0;
      }
      if (a == month && c <= day) {
        printf("YES\n");
        return 0;
      }
    }
  }
  if (good(b, c, a)) {
    if (year - a > 18) {
      printf("YES\n");
      return 0;
    }
    if (year - a == 18) {
      if (c < month) {
        printf("YES\n");
        return 0;
      }
      if (c == month && b <= day) {
        printf("YES\n");
        return 0;
      }
    }
  }
  if (good(c, b, a)) {
    if (year - a > 18) {
      printf("YES\n");
      return 0;
    }
    if (year - a == 18) {
      if (b < month) {
        printf("YES\n");
        return 0;
      }
      if (b == month && c <= day) {
        printf("YES\n");
        return 0;
      }
    }
  }
  printf("NO\n");
  return 0;
}
