#include <bits/stdc++.h>
using namespace std;
int d, m, yr, a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
              b[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool work(int x, int y, int z) {
  if (y > 12 || y == 0) return 0;
  if (z % 4 == 0) {
    if (x == 0 || x > b[y - 1]) return 0;
  } else {
    if (x == 0 || x > a[y - 1]) return 0;
  }
  if (z + 18 > yr) return false;
  if (z + 18 < yr) return true;
  if (m < y) return false;
  if (m > y) return true;
  if (d < x) return false;
  return true;
}
int main() {
  int x, y, z;
  scanf("%d.%d.%d", &d, &m, &yr);
  scanf("%d.%d.%d", &x, &y, &z);
  if (work(x, y, z) || work(x, z, y) || work(y, x, z) || work(y, z, x) ||
      work(z, x, y) || work(z, y, x))
    puts("YES");
  else
    puts("NO");
}
