#include <bits/stdc++.h>
int get(int x, int yy) {
  if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)
    return 31;
  if (x == 4 || x == 6 || x == 9 || x == 11) return 30;
  if (x == 2) {
    if ((2000 + yy) % 400 == 0 || ((2000 + yy) % 4 == 0 && (2000 + yy) % 100))
      return 29;
    else
      return 28;
  }
}
int judge(int dd, int mm, int yy, int b[]) {
  int flag = 0;
  if (yy - b[3] > 18) {
    flag = 1;
  }
  if (yy - b[3] == 18) {
    flag = 1;
    if (mm > b[2]) {
      flag = 1;
    } else if (mm == b[2]) {
      if (dd >= b[1])
        flag = 1;
      else
        flag = 0;
    } else
      flag = 0;
  }
  return flag;
}
int main() {
  int dd, mm, yy;
  int b[4];
  scanf("%2d.%2d.%2d", &dd, &mm, &yy);
  scanf("%2d.%2d.%2d", &b[1], &b[2], &b[3]);
  int ret = 0;
  ret = judge(dd, mm, yy, b);
  if (ret != 0) {
    printf("YES\n");
    return 0;
  }
  if (yy - b[3] >= 18) {
    int ret = 0;
    int aa[5];
    aa[1] = b[2];
    aa[2] = b[1];
    aa[3] = b[3];
    if (b[1] <= 12 && b[1] >= 1) ret = judge(dd, mm, yy, aa);
    if (ret) {
      printf("YES\n");
      return 0;
    }
  }
  if (yy - b[1] >= 18 || yy - b[2] >= 18) {
    int a[5];
    if (yy - b[1] >= 18) {
      if (b[2] <= 12) {
        int days = get(b[2], b[1]);
        if (b[3] >= 1 && b[3] <= days) {
          int ret = 0;
          a[1] = b[3];
          a[2] = b[2];
          a[3] = b[1];
          ret = judge(dd, mm, yy, a);
          if (ret) {
            printf("YES\n");
            return 0;
          }
        }
      }
      int ret = 0;
      a[1] = b[2];
      a[2] = b[3];
      a[3] = b[1];
      if (b[3] <= 12) {
        int days = get(b[3], b[1]);
        if (b[3] >= 1 && b[3] <= days) ret = judge(dd, mm, yy, a);
        if (ret) {
          printf("YES\n");
          return 0;
        }
      }
    }
    if (yy - b[2] >= 18) {
      if (b[1] >= 1 && b[1] <= 12) {
        int days = get(b[1], b[2]), ret = 0;
        a[1] = b[3];
        a[2] = b[1];
        a[3] = b[2];
        if (b[3] <= days) ret = judge(dd, mm, yy, a);
        if (ret) {
          printf("YES\n");
          return 0;
        }
      }
      if (b[3] >= 1 && b[3] <= 12) {
        a[1] = b[1];
        a[2] = b[3];
        a[3] = b[2];
        int days = get(b[3], b[2]), ret = 0;
        if (b[1] <= days) ret = judge(dd, mm, yy, a);
        if (ret) {
          printf("YES\n");
          return 0;
        }
      }
    }
    printf("NO\n");
  } else
    printf("NO\n");
  return 0;
}
