#include <bits/stdc++.h>
using namespace std;
int n;
int m, q;
int a[3];
string dday;
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string tostring(int x) {
  string temp = "";
  for (int i = 0; i < 2; i++) {
    temp = (char)('0' + x % 10) + temp;
    x /= 10;
  }
  return temp;
}
bool solve() {
  sort(a, a + 3);
  do {
    if (a[1] > 12) continue;
    if (a[2] % 4 == 0) {
      if (a[1] == 2 && a[0] > 29) continue;
    } else if (a[1] == 2 && a[0] > 28)
      continue;
    if (a[1] != 2 && a[0] > days[a[1] - 1]) continue;
    a[2] += 18;
    if (a[2] > 100) continue;
    string temp = tostring(a[2]);
    temp.push_back('.');
    temp += tostring(a[1]);
    temp.push_back('.');
    temp += tostring(a[0]);
    if (temp <= dday) {
      return true;
    }
    a[2] -= 18;
  } while (next_permutation(a, a + 3));
  return false;
}
int main() {
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  dday = tostring(a[2]);
  dday.push_back('.');
  dday += tostring(a[1]);
  dday.push_back('.');
  dday += tostring(a[0]);
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  if (solve())
    cout << "YES\n";
  else
    cout << "NO\n";
}
